Crate mongodb[−][src]
Expand description
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/").await?;
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).await? { println!("collection: {}", coll_name); } let coll = db.collection("some-coll"); let result = coll.insert_one(doc! { "x": 1 }, None).await?; println!("{:#?}", result);
Re-exports
pub use bson; |
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. |
| sync | syncContains the sync API. This is only available when the |
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. |