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 uses the [`bson`](https://docs.rs/bson/latest) crate for BSON support. The driver contains a fully async API that requires [`tokio`](https://docs.rs/tokio). The driver also has a sync API that may be enabled via feature flags.
5
-
6
-
For more detailed documentation, see https://www.mongodb.com/docs/drivers/rust/current/. This documentation includes detailed content about features, runnable examples, troubleshooting resources, and more.
7
-
8
-
## Index
9
-
-[Installation](#installation)
10
-
-[Requirements](#requirements)
11
-
-[Supported platforms](#supported-platforms)
12
-
-[Importing](#importing)
13
-
-[Configuring the async runtime](#configuring-the-async-runtime)
14
-
-[Enabling the sync API](#enabling-the-sync-api)
15
-
-[All feature flags](#all-feature-flags)
16
-
-[Example Usage](#example-usage)
17
-
-[Using the async API](#using-the-async-api)
18
-
- [Connecting to a MongoDB deployment](#connecting-to-a-mongodb-deployment)
19
-
- [Getting a handle to a database](#getting-a-handle-to-a-database)
20
-
- [Inserting documents into a collection](#inserting-documents-into-a-collection)
21
-
- [Finding documents in a collection](#finding-documents-in-a-collection)
This is the officially supported MongoDB Rust driver, a client side library that can be used to interact with MongoDB deployments in Rust applications. It uses the [`bson`](https://docs.rs/bson/latest) crate for BSON support. The driver contains a fully async API that requires [`tokio`](https://docs.rs/tokio). The driver also has a sync API that may be enabled via feature flags.
5
+
6
+
For more details, including features, runnable examples, troubleshooting resources, and more, please see the [official documentation](https://www.mongodb.com/docs/drivers/rust/current/).
33
7
34
8
## Installation
35
9
### Requirements
@@ -60,171 +34,18 @@ features = ["sync"]
60
34
61
35
### All Feature Flags
62
36
63
-
| Feature | Description | Extra dependencies | Default |
|`sync`| Expose the synchronous API (`mongodb::sync`). | n/a | no |
66
-
|`aws-auth`| Enable support for the MONGODB-AWS authentication mechanism. |`reqwest`| no |
67
-
|`zlib-compression`| Enable support for compressing messages with [`zlib`](https://zlib.net/)|`flate2`| no |
68
-
|`zstd-compression`| Enable support for compressing messages with [`zstd`](http://facebook.github.io/zstd/). |`zstd`| no |
69
-
|`snappy-compression`| Enable support for compressing messages with [`snappy`](http://google.github.io/snappy/)|`snap`| no |
70
-
|`openssl-tls`| Switch TLS connection handling to use ['openssl'](https://docs.rs/openssl/0.10.38/). |`openssl`| no |
71
-
72
-
## Example Usage
73
-
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/latest).
74
-
75
-
### Using the async API
76
-
#### Connecting to a MongoDB deployment
77
-
```rust
78
-
usemongodb::{Client, options::ClientOptions};
79
-
```
80
-
```rust
81
-
// Parse a connection string into an options struct.
doc! { "title":"The Great Gatsby", "author":"F. Scott Fitzgerald" },
117
-
];
118
-
119
-
// Insert some documents into the "mydb.books" collection.
120
-
collection.insert_many(docs, None).await?;
121
-
```
122
-
123
-
A [`Collection`](https://docs.rs/mongodb/latest/mongodb/struct.Collection.html) can be parameterized with any type that implements the `Serialize` and `Deserialize` traits from the [`serde`](https://serde.rs/) crate, not just `Document`:
124
-
125
-
```toml
126
-
# In Cargo.toml, add the following dependency.
127
-
serde = { version = "1.0", features = ["derive"] }
// Insert the books into "mydb.books" collection, no manual conversion to BSON necessary.
156
-
typed_collection.insert_many(books, None).await?;
157
-
```
158
-
159
-
#### Finding documents in a collection
160
-
Results from queries are generally returned via [`Cursor`](https://docs.rs/mongodb/latest/mongodb/struct.Cursor.html), a struct which streams the results back from the server as requested. The [`Cursor`](https://docs.rs/mongodb/latest/mongodb/struct.Cursor.html) type implements the [`Stream`](https://docs.rs/futures/latest/futures/stream/index.html) trait from the [`futures`](https://crates.io/crates/futures) crate, and in order to access its streaming functionality you need to import at least one of the [`StreamExt`](https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html) or [`TryStreamExt`](https://docs.rs/futures/latest/futures/stream/trait.TryStreamExt.html) traits.
161
-
162
-
```toml
163
-
# In Cargo.toml, add the following dependency.
164
-
futures = "0.3"
165
-
```
166
-
```rust
167
-
// This trait is required to use `try_next()` on the cursor
168
-
usefutures::stream::TryStreamExt;
169
-
usemongodb::{bson::doc, options::FindOptions};
170
-
```
171
-
```rust
172
-
// Query the books in the collection with a filter and an option.
The driver also provides a blocking sync API. See the [Installation](#enabling-the-sync-api) section for instructions on how to enable it.
185
-
186
-
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.
|`dns-resolver`| Enable DNS resolution to allow `mongodb+srv` URI handling. **Enabled by default.**|
40
+
|`rustls-tls`| Use [`rustls`](https://docs.rs/rustls/latest/rustls/) for TLS connection handling. **Enabled by default.**|
41
+
|`openssl-tls`| Use [`openssl`](https://docs.rs/openssl/latest/openssl/) for TLS connection handling. |
42
+
|`sync`| Expose the synchronous API (`mongodb::sync`). |
43
+
|`aws-auth`| Enable support for the MONGODB-AWS authentication mechanism. |
44
+
|`zlib-compression`| Enable support for compressing messages with [`zlib`](https://zlib.net/)|
45
+
|`zstd-compression`| Enable support for compressing messages with [`zstd`](http://facebook.github.io/zstd/). |
46
+
|`snappy-compression`| Enable support for compressing messages with [`snappy`](http://google.github.io/snappy/)|
47
+
|`in-use-encryption-unstable`| Enable support for client-side field level encryption and queryable encryption. This API is unstable and may be subject to breaking changes in minor releases. |
48
+
|`tracing-unstable`| Enable support for emitting [`tracing`](https://docs.rs/tracing/latest/tracing/) events. This API is unstable and may be subject to breaking changes in minor releases. |
228
49
229
50
## Web Framework Examples
230
51
### Actix
@@ -239,24 +60,7 @@ In order to connect to a pre-4.2 Atlas instance that's M2 or bigger, the `openss
239
60
240
61
## Windows DNS note
241
62
242
-
On Windows, there is a known issue in the `trust-dns-resolver` crate, which the driver uses to perform DNS lookups, that causes severe performance degradation in resolvers that use the system configuration. Since the driver uses the system configuration by default, users are recommended to specify an alternate resolver configuration on Windows until that issue is resolved. This only has an effect when connecting to deployments using a `mongodb+srv` connection string.
On Windows, there is a known issue in the `trust-dns-resolver` crate, which the driver uses to perform DNS lookups, that causes severe performance degradation in resolvers that use the system configuration. Since the driver uses the system configuration by default, users are recommended to specify an alternate resolver configuration on Windows (e.g. `ResolverConfig::cloudflare()`) until that issue is resolved. This only has an effect when connecting to deployments using a `mongodb+srv` connection string.
260
64
261
65
## Warning about timeouts / cancellation
262
66
@@ -272,16 +76,6 @@ one option is to spawn tasks and time out on their
272
76
the driver's futures directly. This will ensure the driver's futures will always be completely polled
273
77
while also allowing the application to continue in the event of a timeout.
0 commit comments