"hu mongo us"
Document-oriented database
Just like discovering dynamic languages for the 1st time (plus it maps smoothly to dynamic languages).
Not exactly schema less (more of dynamic one):
Collections are created as needed (on write).
{
_id: "September 19th, 2012",
talks: [
{
title: "Meta-Moose",
lecturer: "Ynon Perek",
description: "Using the meta object, dyna ..."
slides: "http://www.slideshare.net/YnonPerek/metamoose-14339965"
},
{
title: "Project Euler",
lecturer: "Shlomi Fish",
}, { ... }
]
}
Basically a JS shell. Let's play with it a bit.
db.products.find({'type': 'case'})
Find all documents in collection products where type is "case" (even if type is an array).
Many query operators, like
Some of the update operators (in addition to save() ):
Has official support for many languages:
C, C++, C# / .NET, Erlang, Haskell, Java, JavaScript, Lisp, node.JS, Perl, PHP, Python, Ruby, Scala
Plus few unofficial ones.
For Perl, there's MongoDB at CPAN
use MongoDB;
my $conn = MongoDB::Connection->new;
my $catalog_db = $conn->pcat; # pcat db
my $products = $catalog_db->products; # products collection
my $services = $products->find({type => "service"}); # we get a cursor
while (my $service = $services->next) {
print $service->{'_id'} . ', ' . $service->{'name'} . "\n";
}
$products->insert({
name => "Dummy box", type => ["service", "dummy"]
});
# or
$catalog_db->products->insert({
name => "Dummy box", type => ["service", "dummy"]
});
# For type service increment price by 20, set the raised flag
$products->update(
{type => "service"},
{'$inc' => {monthly_price => 20}, {'$set' => {raised => 1}} }
);
# with boolean. To get booleans set $MongoDB::BSON::use_boolean to 1
use boolean;
$products->update(
{type => "service"},
{'$inc' => {monthly_price => 20}, {'$set' => {raised =>true}} }
);
Let's talk a bit about capped collections and tailabile cursors.
my $cursor = $coll->find->tailable(1);
for (;;) {
if (defined(my $doc = $cursor->next)) {
say $doc;
}
else {
sleep 1;
}
}