| MongoDB::Database - A Mongo database |
last_error($options?)
MongoDB::Database - A Mongo database
The MongoDB::Database class accesses to a database.
# accesses the foo database
my $db = $connection->foo;
You can also access databases with the get_database($name) in the MongoDB::Connection manpage method.
Core documentation on databases: http://dochub.mongodb.org/core/databases.
The name of the database.
my @collections = $database->collection_names;
Returns the list of collections in this database.
my $collection = $database->get_collection('foo');
Returns a the MongoDB::Collection manpage for the collection called $name within this
database.
my $grid = $database->get_gridfs;
Returns a the MongoDB::GridFS manpage for storing and retrieving files from the database.
Default prefix is "fs", making $grid->files "fs.files" and $grid->chunks
"fs.chunks".
See the MongoDB::GridFS manpage for more information.
$database->drop;
Deletes the database.
last_error($options?)
my $err = $db->last_error({w => 2});
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 occured.
The optional $options parameter is a hash reference that can contain any of
the following:
Guarantees that the previous operation will be replicated to w servers before
this command will return success. See MongoDB::Connection::w for more
information.
Milliseconds to wait for w copies of the data to be made. This parameter
should generally be specified, as the database will otherwise wait forever if
w copies cannot be made.
If true, the database will fsync to disk before returning.
See w in the MongoDB::Connection manpage for more information.
my $result = $database->run_command({ some_command => 1 });
Runs a database command. Throws an exception with an error message if the command fails. Returns the result of the command on success. For a list of possible database commands, run:
my $commands = $db->run_command({listCommands : 1});
See also core documentation on database commands: http://dochub.mongodb.org/core/commands.
my $result = $database->eval('function(x) { return "hello, "+x; }', ["world"]);
Evaluate a JavaScript expression on the Mongo server. The $code argument can
be a string or an instance of the MongoDB::Code manpage. The $args are an optional
array of arguments to be passed to the $code function.
eval 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 $code argument
must be a JavaScript function. $args is an array of parameters that will be
passed to the function. For more examples of using eval see
http://www.mongodb.org/display/DOCS/Server-side+Code+Execution#Server-sideCodeExecution-Using{{db.eval%28%29}}.
Kristina Chodorow <kristina@mongodb.org>
| MongoDB::Database - A Mongo database |