1Mango::Database(3)    User Contributed Perl Documentation   Mango::Database(3)
2
3
4

NAME

6       Mango::Database - MongoDB database
7

SYNOPSIS

9         use Mango::Database;
10
11         my $db = Mango::Database->new(mango => $mango);
12         my $collection = $db->collection('foo');
13         my $gridfs     = $db->gridfs;
14

DESCRIPTION

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

ATTRIBUTES

19       Mango::Database implements the following attributes.
20
21   mango
22         my $mango = $db->mango;
23         $db       = $db->mango(Mango->new);
24
25       Mango object this database belongs to. Note that this reference is
26       usually weakened, so the Mango object needs to be referenced elsewhere
27       as well.
28
29   name
30         my $name = $db->name;
31         $db      = $db->name('bar');
32
33       Name of this database.
34

METHODS

36       Mango::Database inherits all methods from Mojo::Base and implements the
37       following new ones.
38
39   build_write_concern
40         my $concern = $db->build_write_concern;
41
42       Build write concern based on l</"mango"> settings.
43
44   collection
45         my $collection = $db->collection('foo');
46
47       Build Mango::Collection object for collection.
48
49   collection_names
50         my $names = $db->collection_names;
51
52       Names of all collections in this database. You can filter the results
53       by using the same arguments as for "list_collections". You can also
54       append a callback to perform operation non-blocking.
55
56         $db->collection_names(sub {
57           my ($db, $err, $names) = @_;
58           ...
59         });
60         Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
61
62   command
63         my $doc = $db->command(bson_doc(text => 'foo.bar', search => 'test'));
64         my $doc = $db->command(bson_doc(getLastError => 1, w => 2));
65         my $doc = $db->command('getLastError', w => 2);
66
67       Run command against database. You can also append a callback to run
68       command non-blocking.
69
70         $db->command(('getLastError', w => 2) => sub {
71           my ($db, $err, $doc) = @_;
72           ...
73         });
74         Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
75
76   dereference
77         my $doc = $db->dereference($dbref);
78
79       Resolve database reference. You can also append a callback to perform
80       operation non-blocking.
81
82         $db->dereference($dbref => sub {
83           my ($db, $err, $doc) = @_;
84           ...
85         });
86         Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
87
88   gridfs
89         my $gridfs = $db->gridfs;
90
91       Build Mango::GridFS object.
92
93   list_collections
94         # return a cursor for all collections
95         my $cursor = $db->list_collections;
96         # only collections which name matchs a regex
97         my $cursor = $db->list_collections(filter => { name => qr{^prefix} });
98         # only capped collections
99         my $cursor = $db->list_collections(filter => { 'options.capped' => 1 });
100         # only the first 10 collections
101         my $cursor = $db->list_collections(cursor => { batchSize => 10 });
102
103       Returns a Mango::Cursor of all collections in this database. Each
104       collection is represented by a document containing at least the keys
105       "name" and "options". You can also append a callback to perform
106       operation non-blocking.
107
108         $db->list_collections(sub {
109           my ($db, $err, $cursor) = @_;
110           ...
111         });
112         Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
113
114   stats
115         my $stats = $db->stats;
116
117       Get database statistics. You can also append a callback to perform
118       operation non-blocking.
119
120         $db->stats(sub {
121           my ($db, $err, $stats) = @_;
122           ...
123         });
124         Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
125

SEE ALSO

127       Mango, Mojolicious::Guides, <http://mojolicio.us>.
128
129
130
131perl v5.30.0                      2019-07-26                Mango::Database(3)
Impressum