.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" 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 turned on, 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 .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "MongoDB::Database 3pm" .TH MongoDB::Database 3pm "2014-10-09" "perl v5.20.1" "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" MongoDB::Database \- A MongoDB Database .SH "VERSION" .IX Header "VERSION" version v0.705.0.0 .SH "SYNOPSIS" .IX Header "SYNOPSIS" The MongoDB::Database class accesses to a database. .PP .Vb 2 \& # accesses the foo database \& my $db = $connection\->foo; .Ve .PP You can also access databases with the \*(L"get_database($name)\*(R" in MongoDB::Connection method. .SH "NAME" MongoDB::Database \- A Mongo database .SH "SEE ALSO" .IX Header "SEE ALSO" Core documentation on databases: . .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" .SS "name" .IX Subsection "name" The name of the database. .SH "METHODS" .IX Header "METHODS" .SS "collection_names" .IX Subsection "collection_names" .Vb 1 \& my @collections = $database\->collection_names; .Ve .PP Returns the list of collections in this database. .SS "get_collection ($name)" .IX Subsection "get_collection ($name)" .Vb 1 \& my $collection = $database\->get_collection(\*(Aqfoo\*(Aq); .Ve .PP Returns a MongoDB::Collection for the collection called \f(CW$name\fR within this database. .SS "get_gridfs ($prefix?)" .IX Subsection "get_gridfs ($prefix?)" .Vb 1 \& my $grid = $database\->get_gridfs; .Ve .PP Returns a MongoDB::GridFS for storing and retrieving files from the database. Default prefix is \*(L"fs\*(R", making \f(CW\*(C`$grid\->files\*(C'\fR \*(L"fs.files\*(R" and \f(CW\*(C`$grid\->chunks\*(C'\fR \&\*(L"fs.chunks\*(R". .PP See MongoDB::GridFS for more information. .SS "drop" .IX Subsection "drop" .Vb 1 \& $database\->drop; .Ve .PP Deletes the database. .SS "last_error($options?)" .IX Subsection "last_error($options?)" .Vb 1 \& my $err = $db\->last_error({w => 2}); .Ve .PP Finds out if the last database operation completed successfully. If the last operation did not complete successfully, returns a hash reference of information about the error that occurred. .PP The optional \f(CW$options\fR parameter is a hash reference that can contain any of the following: .IP "w" 4 .IX Item "w" Guarantees that the previous operation will be replicated to \f(CW\*(C`w\*(C'\fR servers before this command will return success. See \f(CW\*(C`MongoDB::Connection::w\*(C'\fR for more information. .IP "wtimeout" 4 .IX Item "wtimeout" Milliseconds to wait for \f(CW\*(C`w\*(C'\fR copies of the data to be made. This parameter should generally be specified, as the database will otherwise wait forever if \&\f(CW\*(C`w\*(C'\fR copies cannot be made. .IP "fsync" 4 .IX Item "fsync" If true, behaves identically to \f(CW\*(C`j\*(C'\fR if journaling has been turned on for \f(CW\*(C`mongod\*(C'\fR. .Sp If \f(CW\*(C`mongod\*(C'\fR is not running with journaling, then this option requests that writes be immediately \f(CW\*(C`sync\*(C'\fRed to disk if true. .Sp This option can not be used simultaneously with the \f(CW\*(C`j\*(C'\fR flag. .IP "j" 4 .IX Item "j" If true, the client will block until write operations have been committed to the server's journal. Prior to MongoDB 2.6, this option was ignored if the server was running without journaling. Starting with MongoDB 2.6, write operations will fail if this option is used when the server is running without journaling. .PP \&\f(CW\*(C`last_error\*(C'\fR returns a hash with fields that vary, depending on what the previous operation was and if it succeeded or failed. If the last operation (before the \f(CW\*(C`last_error\*(C'\fR call) failed, either: .ie n .IP """err"" will be set or" 4 .el .IP "\f(CWerr\fR will be set or" 4 .IX Item "err will be set or" .PD 0 .ie n .IP """errmsg"" will be set and ""ok"" will be 0." 4 .el .IP "\f(CWerrmsg\fR will be set and \f(CWok\fR will be 0." 4 .IX Item "errmsg will be set and ok will be 0." .PD .PP If \f(CW\*(C`err\*(C'\fR is \f(CW\*(C`null\*(C'\fR and \f(CW\*(C`ok\*(C'\fR is 1, the previous operation succeeded. .PP The fields in the hash returned can include (but are not limited to): .ie n .IP """ok""" 4 .el .IP "\f(CWok\fR" 4 .IX Item "ok" This should almost be 1 (unless \f(CW\*(C`last_error\*(C'\fR itself failed). .ie n .IP """err""" 4 .el .IP "\f(CWerr\fR" 4 .IX Item "err" If this field is non-null, an error occurred on the previous operation. If this field is set, it will be a string describing the error that occurred. .ie n .IP """code""" 4 .el .IP "\f(CWcode\fR" 4 .IX Item "code" If a database error occurred, the relevant error code will be passed back to the client. .ie n .IP """errmsg""" 4 .el .IP "\f(CWerrmsg\fR" 4 .IX Item "errmsg" This field is set if something goes wrong with a database command. It is coupled with \f(CW\*(C`ok\*(C'\fR being 0. For example, if \f(CW\*(C`w\*(C'\fR is set and times out, \&\f(CW\*(C`errmsg\*(C'\fR will be set to \*(L"timed out waiting for slaves\*(R" and \f(CW\*(C`ok\*(C'\fR will be 0. If this field is set, it will be a string describing the error that occurred. .ie n .IP """n""" 4 .el .IP "\f(CWn\fR" 4 .IX Item "n" If the last operation was an update, upsert, or a remove, the number of objects affected will be returned. .ie n .IP """wtimeout""" 4 .el .IP "\f(CWwtimeout\fR" 4 .IX Item "wtimeout" If the previous option timed out waiting for replication. .ie n .IP """waited""" 4 .el .IP "\f(CWwaited\fR" 4 .IX Item "waited" How long the operation waited before timing out. .ie n .IP """wtime""" 4 .el .IP "\f(CWwtime\fR" 4 .IX Item "wtime" If \f(CW\*(C`w\*(C'\fR was set and the operation succeeded, how long it took to replicate to \&\f(CW\*(C`w\*(C'\fR servers. .ie n .IP """upserted""" 4 .el .IP "\f(CWupserted\fR" 4 .IX Item "upserted" If an upsert occurred, this field will contain the new record's \f(CW\*(C`_id\*(C'\fR field. For upserts, either this field or \f(CW\*(C`updatedExisting\*(C'\fR will be present (unless an error occurred). .ie n .IP """updatedExisting""" 4 .el .IP "\f(CWupdatedExisting\fR" 4 .IX Item "updatedExisting" If an upsert updated an existing element, this field will be \f(CW\*(C`true\*(C'\fR. For upserts, either this field or \f(CW\*(C`upserted\*(C'\fR will be present (unless an error occurred). .PP See \*(L"w\*(R" in MongoDB::Connection for more information. .SS "run_command ($command)" .IX Subsection "run_command ($command)" .Vb 1 \& my $result = $database\->run_command({ some_command => 1 }); .Ve .PP Runs a database command. Returns a string with the error message if the command fails. Returns the result of the command (a hash reference) on success. For a list of possible database commands, run: .PP .Vb 1 \& my $commands = $db\->run_command({listCommands => 1}); .Ve .PP There are a few examples of database commands in the \&\*(L"\s-1DATABASE COMMANDS\*(R"\s0 in MongoDB::Examples section. .PP See also core documentation on database commands: . .ie n .SS "eval ($code, $args?, $nolock?)" .el .SS "eval ($code, \f(CW$args\fP?, \f(CW$nolock\fP?)" .IX Subsection "eval ($code, $args?, $nolock?)" .Vb 1 \& my $result = $database\->eval(\*(Aqfunction(x) { return "hello, "+x; }\*(Aq, ["world"]); .Ve .PP Evaluate a JavaScript expression on the Mongo server. The \f(CW$code\fR argument can be a string or an instance of MongoDB::Code. The \f(CW$args\fR are an optional array of arguments to be passed to the \f(CW$code\fR function. \f(CW$nolock\fR (default \&\f(CW\*(C`false\*(C'\fR) prevents the eval command from taking the global write lock before evaluating the JavaScript. .PP \&\f(CW\*(C`eval\*(C'\fR is useful if you need to touch a lot of data lightly; in such a scenario the network transfer of the data could be a bottleneck. The \f(CW$code\fR argument must be a JavaScript function. \f(CW$args\fR is an array of parameters that will be passed to the function. \f(CW$nolock\fR is a boolean value. For more examples of using eval see . .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 David Golden .IP "\(bu" 4 Mike Friedman .IP "\(bu" 4 Kristina Chodorow .IP "\(bu" 4 Florian Ragwitz .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2014 by MongoDB, Inc.. .PP This is free software, licensed under: .PP .Vb 1 \& The Apache License, Version 2.0, January 2004 .Ve