NAME
Mango::Database - MongoDB database
SYNOPSIS
use Mango::Database;
my $db = Mango::Database->new(mango => $mango);
my $collection = $db->collection('foo');
my $gridfs = $db->gridfs;
DESCRIPTION
Mango::Database is a container for MongoDB databases used by Mango.
ATTRIBUTES
Mango::Database implements the following attributes.
mango
my $mango = $db->mango;
$db = $db->mango(Mango->new);
Mango object this database belongs to. Note that this reference is usually weakened, so the Mango object needs to be referenced elsewhere as well.
name
my $name = $db->name;
$db = $db->name('bar');
Name of this database.
METHODS
Mango::Database inherits all methods from Mojo::Base and implements the following new ones.
collection
my $collection = $db->collection('foo');
Get Mango::Collection object for collection.
collection_names
my $names = $db->collection_names;
Names of all collections in this database. You can also append a callback to perform operation non-blocking.
$db->collection_names(sub {
my ($db, $err, $names) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
command
my $doc = $db->command(bson_doc(text => 'foo.bar', search => 'test'));
my $doc = $db->command(bson_doc(getLastError => 1, w => 2));
my $doc = $db->command('getLastError', w => 2);
Run command against database. You can also append a callback to run command non-blocking.
$db->command(('getLastError', w => 2) => sub {
my ($db, $err, $doc) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
dereference
my $doc = $db->dereference($dbref);
Resolve database reference. You can also append a callback to perform operation non-blocking.
$db->dereference($dbref => sub {
my ($db, $err, $doc) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
gridfs
my $gridfs = $db->gridfs;
Get Mango::GridFS object.
stats
my $stats = $db->stats;
Get database statistics. You can also append a callback to perform operation non-blocking.
$db->stats(sub {
my ($db, $err, $stats) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;