[−][src]Crate mongodb
This crate is a pure Rust MongoDB driver. It follows the MongoDB driver API and feature specifications.
To connect to a MongoDB database, pass a MongoDB connection string to
Client::with_uri_str
:
let client = Client::with_uri_str("mongodb://localhost:27017/")?;
Alternately, create an instance of ClientOptions
and pass
it to Client::with_options
:
let options = ClientOptions::builder() .hosts(vec![ StreamAddress { hostname: "localhost".into(), port: Some(27017), } ]) .build(); let client = Client::with_options(options)?;
Operations can be performed by obtaining a Database
or
Collection
from the Client
:
let db = client.database("some_db"); for coll_name in db.list_collection_names(None)? { println!("collection: {}", coll_name); } let coll = db.collection("some-coll"); let result = coll.insert_one(doc! { "x": 1 }, None)?; println!("{:#?}", result);
Modules
error | Contains the |
event | Contains the events and functionality for monitoring internal |
options | Contains all of the types needed to specify options to MongoDB operations. |
results | Contains the types of results returned by CRUD operations. |
Structs
Client | This is the main entry point for the API. A |
Collection |
|
Cursor | A |
Database |
|
Namespace | A struct modeling the canonical name for a collection in MongoDB. |