GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Mango::Database(3) User Contributed Perl Documentation Mango::Database(3)

Mango::Database - MongoDB database

  use Mango::Database;

  my $db = Mango::Database->new(mango => $mango);
  my $collection = $db->collection('foo');
  my $gridfs     = $db->gridfs;

Mango::Database is a container for MongoDB databases used by Mango.

Mango::Database implements the following attributes.

  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.

  my $name = $db->name;
  $db      = $db->name('bar');

Name of this database.

Mango::Database inherits all methods from Mojo::Base and implements the following new ones.

  my $concern = $db->build_write_concern;

Build write concern based on l</"mango"> settings.

  my $collection = $db->collection('foo');

Build Mango::Collection object for collection.

  my $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;

  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;

  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;

  my $gridfs = $db->gridfs;

Build Mango::GridFS object.

  # 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;

  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;

Mango, Mojolicious::Guides, <http://mojolicio.us>.
2018-03-17 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.