Installation and Features

Importing

The driver is available on crates.io. To use the driver in your application, simply add it to your project's Cargo.toml.

[dependencies]
mongodb = "2.1.0"

Configuring the async runtime

The driver supports both of the most popular async runtime crates, namely tokio and async-std. By default, the driver will use tokio, but you can explicitly choose a runtime by specifying one of "tokio-runtime" or "async-std-runtime" feature flags in your Cargo.toml.

For example, to instruct the driver to work with async-std, add the following to your Cargo.toml:

[dependencies.mongodb]
version = "2.7.0"
default-features = false
features = ["async-std-runtime"]

Enabling the sync API

The driver also provides a blocking sync API. To enable this, add the "sync" or "tokio-sync" feature to your Cargo.toml:

[dependencies.mongodb]
version = "2.7.0"
features = ["tokio-sync"]

Using the "sync" feature also requires using default-features = false. Note: The sync-specific types can be imported from mongodb::sync (e.g. mongodb::sync::Client).

All Feature Flags

FeatureDescriptionExtra dependenciesDefault
tokio-runtimeEnable support for the tokio async runtimetokio 1.0 with the full featureyes
async-std-runtimeEnable support for the async-std runtimeasync-std 1.0no
syncExpose the synchronous API (mongodb::sync), using an async-std backend. Cannot be used with the tokio-runtime feature flag.async-std 1.0no
tokio-syncExpose the synchronous API (mongodb::sync), using a tokio backend. Cannot be used with the async-std-runtime feature flag.tokio 1.0 with the full featureno
aws-authEnable support for the MONGODB-AWS authentication mechanism.reqwest 0.11no
bson-uuid-0_8Enable support for v0.8 of the uuid crate in the public API of the re-exported bson crate.n/ano
bson-uuid-1Enable support for v1.x of the uuid crate in the public API of the re-exported bson crate.n/ano
bson-chrono-0_4Enable support for v0.4 of the chrono crate in the public API of the re-exported bson crate.n/ano
bson-serde_withEnable support for the serde_with crate in the public API of the re-exported bson crate.serde_with 1.0no
zlib-compressionEnable support for compressing messages with zlibflate2 1.0no
zstd-compressionEnable support for compressing messages with zstd. This flag requires Rust version 1.54.zstd 0.9.0no
snappy-compressionEnable support for compressing messages with snappysnap 1.0.5no
openssl-tlsSwitch TLS connection handling to use 'openssl'.openssl 0.10.38no