Module mongodb::db
[−]
[src]
Interface for database-level operations.
Usage
The database API provides methods for opening, creating, deleting, and listing collections. It also handles user-level authentication over SCRAM-SHA-1.
Collection Operations
let db = client.db("movies"); db.create_collection("action", None).unwrap(); let collection_names = db.collection_names(None).unwrap(); assert!(!collection_names.is_empty());
Authentication
let db = client.db("redacted"); db.create_user("saghm", "1234", None).unwrap(); db.auth("saghm", "1234").unwrap(); let success = db.list_collections(None).unwrap();
Arbitrary Database Commands
Any valid MongoDB database command can be sent to the server with the command
and command_cursor
functions.
let db = client.db("movies"); let cmd = doc! { "connectionStatus" => 1 }; let result = db.command(cmd, CommandType::Suppressed, None).unwrap(); if let Some(&Bson::Document(ref doc)) = result.get("authInfo") { // Read authentication info. }
Modules
options |
Options for database-level commands. |
roles |
Role-based database and command authorization. |
Structs
DatabaseInner |
Interfaces with a MongoDB database. |
Traits
ThreadedDatabase |
Type Definitions
Database |