|
NAMEMango::Database - MongoDB databaseSYNOPSISuse Mango::Database; my $db = Mango::Database->new(mango => $mango); my $collection = $db->collection('foo'); my $gridfs = $db->gridfs; DESCRIPTIONMango::Database is a container for MongoDB databases used by Mango.ATTRIBUTESMango::Database implements the following attributes.mangomy $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. namemy $name = $db->name; $db = $db->name('bar'); Name of this database. METHODSMango::Database inherits all methods from Mojo::Base and implements the following new ones.build_write_concernmy $concern = $db->build_write_concern; Build write concern based on l</"mango"> settings. collectionmy $collection = $db->collection('foo'); Build Mango::Collection object for collection. collection_namesmy $names = $db->collection_names; Names of all collections in this database. You can filter the results by using the same arguments as for "list_collections". 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; commandmy $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; dereferencemy $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; gridfsmy $gridfs = $db->gridfs; Build Mango::GridFS object. list_collections# return a cursor for all collections my $cursor = $db->list_collections; # only collections which name matchs a regex my $cursor = $db->list_collections(filter => { name => qr{^prefix} }); # only capped collections my $cursor = $db->list_collections(filter => { 'options.capped' => 1 }); # only the first 10 collections my $cursor = $db->list_collections(cursor => { batchSize => 10 }); Returns a Mango::Cursor of all collections in this database. Each collection is represented by a document containing at least the keys "name" and "options". You can also append a callback to perform operation non-blocking. $db->list_collections(sub { my ($db, $err, $cursor) = @_; ... }); Mojo::IOLoop->start unless Mojo::IOLoop->is_running; statsmy $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; SEE ALSOMango, Mojolicious::Guides, <http://mojolicio.us>.
Visit the GSP FreeBSD Man Page Interface. |