The MongoDB Rust driver is a client library for Rust apps, with async tokio APIs, optional sync API, and BSON via the bson crate. Published on crates.io.
Overview
The MongoDB Rust driver is the officially supported client-side library for Rust programs that interact with MongoDB deployments. It uses the bson crate for BSON and exposes a fully async API that requires tokio. A blocking sync API can be enabled through Cargo feature flags, with types under mongodb::sync.
Documentation covers installation via Cargo.toml, connections, databases and collections, CRUD, aggregation, BSON and Rust type conversion, indexes, MongoDB Search, MongoDB Vector Search, monitoring, logging, security, compatibility, and operation error handling. Example integrations are described for Actix, Axum, and Rocket.
Cargo features add DNS resolution for mongodb+srv URIs, AWS authentication, zstd and snappy compression, client-side field level encryption, SOCKS5 proxy support, and other optional behavior. The driver follows semantic versioning; users on older major lines are directed to migration notes when upgrading.
CI exercises the driver on Linux, macOS, and Windows. Guidance warns that dropping driver futures early for timeouts can leave internal state inconsistent and recommends polling driver futures to completion or timing out JoinHandle tasks instead.
Key features
- Async API with tokio
- Optional sync API feature
- BSON crate integration
- CRUD and aggregation
- mongodb+srv DNS resolution
- Snappy and zstd compression features
- Client-side field level encryption
- Web framework examples
Use cases
- Rust services using MongoDB
- Actix or Axum apps with shared Client
- Blocking code paths via sync feature
- Encrypted or compressed MongoDB traffic
- Search queries from Rust