.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mango::Database 3pm" .TH Mango::Database 3pm "2020-06-05" "perl v5.30.3" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mango::Database \- MongoDB database .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mango::Database; \& \& my $db = Mango::Database\->new(mango => $mango); \& my $collection = $db\->collection(\*(Aqfoo\*(Aq); \& my $gridfs = $db\->gridfs; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mango::Database is a container for MongoDB databases used by Mango. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mango::Database implements the following attributes. .SS "mango" .IX Subsection "mango" .Vb 2 \& my $mango = $db\->mango; \& $db = $db\->mango(Mango\->new); .Ve .PP Mango object this database belongs to. Note that this reference is usually weakened, so the Mango object needs to be referenced elsewhere as well. .SS "name" .IX Subsection "name" .Vb 2 \& my $name = $db\->name; \& $db = $db\->name(\*(Aqbar\*(Aq); .Ve .PP Name of this database. .SH "METHODS" .IX Header "METHODS" Mango::Database inherits all methods from Mojo::Base and implements the following new ones. .SS "build_write_concern" .IX Subsection "build_write_concern" .Vb 1 \& my $concern = $db\->build_write_concern; .Ve .PP Build write concern based on l settings. .SS "collection" .IX Subsection "collection" .Vb 1 \& my $collection = $db\->collection(\*(Aqfoo\*(Aq); .Ve .PP Build Mango::Collection object for collection. .SS "collection_names" .IX Subsection "collection_names" .Vb 1 \& my $names = $db\->collection_names; .Ve .PP Names of all collections in this database. You can filter the results by using the same arguments as for \f(CW\*(C`list_collections\*(C'\fR. You can also append a callback to perform operation non-blocking. .PP .Vb 5 \& $db\->collection_names(sub { \& my ($db, $err, $names) = @_; \& ... \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .SS "command" .IX Subsection "command" .Vb 3 \& my $doc = $db\->command(bson_doc(text => \*(Aqfoo.bar\*(Aq, search => \*(Aqtest\*(Aq)); \& my $doc = $db\->command(bson_doc(getLastError => 1, w => 2)); \& my $doc = $db\->command(\*(AqgetLastError\*(Aq, w => 2); .Ve .PP Run command against database. You can also append a callback to run command non-blocking. .PP .Vb 5 \& $db\->command((\*(AqgetLastError\*(Aq, w => 2) => sub { \& my ($db, $err, $doc) = @_; \& ... \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .SS "dereference" .IX Subsection "dereference" .Vb 1 \& my $doc = $db\->dereference($dbref); .Ve .PP Resolve database reference. You can also append a callback to perform operation non-blocking. .PP .Vb 5 \& $db\->dereference($dbref => sub { \& my ($db, $err, $doc) = @_; \& ... \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .SS "gridfs" .IX Subsection "gridfs" .Vb 1 \& my $gridfs = $db\->gridfs; .Ve .PP Build Mango::GridFS object. .SS "list_collections" .IX Subsection "list_collections" .Vb 8 \& # 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 => { \*(Aqoptions.capped\*(Aq => 1 }); \& # only the first 10 collections \& my $cursor = $db\->list_collections(cursor => { batchSize => 10 }); .Ve .PP Returns a Mango::Cursor of all collections in this database. Each collection is represented by a document containing at least the keys \f(CW\*(C`name\*(C'\fR and \&\f(CW\*(C`options\*(C'\fR. You can also append a callback to perform operation non-blocking. .PP .Vb 5 \& $db\->list_collections(sub { \& my ($db, $err, $cursor) = @_; \& ... \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .SS "stats" .IX Subsection "stats" .Vb 1 \& my $stats = $db\->stats; .Ve .PP Get database statistics. You can also append a callback to perform operation non-blocking. .PP .Vb 5 \& $db\->stats(sub { \& my ($db, $err, $stats) = @_; \& ... \& }); \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Mango, Mojolicious::Guides, .