You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repository contains the officially supported MongoDB Rust driver, a client side library that can be used to interact with MongoDB deployments in Rust applications. It depends on the community-supported [`bson`](https://docs.rs/bson)library for BSON support.
4
+
This repository contains the officially supported MongoDB Rust driver, a client side library that can be used to interact with MongoDB deployments in Rust applications. It depends on the [`bson`](https://docs.rs/bson)crate for BSON support. The driver contains a fully async API that supports either [`tokio`](https://crates.io/crates/tokio) (default) or [`async-std`](https://crates.io/crates/async-std), depending on the feature flags set. The driver also has a sync API that may be enabled via feature flag.
5
5
6
6
## Index
7
7
-[Installation](#Installation)
8
+
-[Importing](#importing)
9
+
- [Configuring the async runtime](#configuring-the-async-runtime)
10
+
- [Enabling the sync API](#enabling-the-sync-api)
8
11
-[Example Usage](#example-usage)
9
-
-[Connecting to a MongoDB deployment](#connecting-to-a-mongodb-deployment)
10
-
-[Getting a handle to a database](#getting-a-handle-to-a-database)
11
-
-[Inserting documents into a collection](#inserting-documents-into-a-collection)
12
-
-[Finding documents in a collection](#finding-documents-in-a-collection)
12
+
-[Using the async API](#using-the-async-api)
13
+
- [Connecting to a MongoDB deployment](#connecting-to-a-mongodb-deployment)
14
+
- [Getting a handle to a database](#getting-a-handle-to-a-database)
15
+
- [Inserting documents into a collection](#inserting-documents-into-a-collection)
16
+
- [Finding documents in a collection](#finding-documents-in-a-collection)
The driver supports both of the most popular async runtime crates, namely [`tokio`](https://crates.io/crates/tokio) and [`async-std`](https://crates.io/crates/async-std). By default, the driver will use [`tokio`](https://crates.io/crates/tokio), but you can explicitly choose a runtime by specifying one of `"tokio-runtime"` or `"async-std-runtime"` feature flags in your `Cargo.toml`.
43
+
44
+
For example, to instruct the driver to work with [`async-std`](https://crates.io/crates/async-std), add the following to your `Cargo.toml`:
45
+
```toml
46
+
[dependencies.mongodb]
47
+
version = "0.10.0"
48
+
default-features = false
49
+
features = ["async-std-runtime"]
50
+
```
51
+
52
+
#### Enabling the sync API
53
+
The driver also provides a blocking sync API. To enable this, add the `"sync"` feature to your `Cargo.toml`:
54
+
```toml
55
+
[dependencies.mongodb]
56
+
version = "0.10.0"
57
+
default-features = false
58
+
features = ["sync"]
59
+
```
60
+
**Note:** if the sync API is enabled, the async-specific types will be privatized (e.g. `mongodb::Client`). The sync-specific types can be imported from `mongodb::sync` (e.g. `mongodb::sync::Client`).
61
+
36
62
## Example Usage
37
63
Below are simple examples of using the driver. For more specific examples and the API reference, see the driver's [docs.rs page](https://docs.rs/mongodb).
38
-
### Connecting to a MongoDB deployment
64
+
65
+
### Using the async API
66
+
#### Connecting to a MongoDB deployment
39
67
```rust
40
68
usemongodb::{Client, options::ClientOptions};
41
69
```
42
70
```rust
43
71
// Parse a connection string into an options struct.
The driver also provides a blocking sync API. See the [Installation](#enabling-the-sync-api) section for instructions on how to enable it.
141
+
142
+
The various sync-specific types are found in the `mongodb::sync` submodule rather than in the crate's top level like in the async API. The sync API calls through to the async API internally though, so it looks and behaves similarly to it.
Currently, the driver has issues connecting to Atlas tiers above M2 unless the server version is at least 4.2. We're working on fixing this, but in the meantime, a workaround is to upgrade your cluster to 4.2. The driver has no known issues with either M0 or M2 instances.
@@ -162,7 +228,7 @@ To run the tests with TLS/SSL enabled, you must enable it on the deployment and
**Note:** When you open a pull request, your code will be run against a comprehensive testing matrix, so it is usually not necessary run the integration tests against all combinations of topology/auth/TLS locally.
231
+
**Note:** When you open a pull request, your code will be run against a comprehensive testing matrix, so it is usually not necessary to run the integration tests against all combinations of topology/auth/TLS locally.
166
232
167
233
### Linter Tests
168
234
Our linter tests use the nightly version of `rustfmt` to verify that the source is formatted properly and the stable version of `clippy` to statically detect any common mistakes.
0 commit comments