Docs Menu
Docs Home
/ / /
Rust Driver
/

Download and Install

1

Ensure you have Rust 1.60 or later, and Cargo, the Rust package manager, installed in your development environment.

For information about how to install Rust and Cargo, see the official Rust guide on downloading and installing Rust.

2

In your shell, run the following command to create a directory called rust_quickstart for this project:

cargo new rust_quickstart

When this command successfully completes, you have a Cargo.toml file and a src directory with a main.rs file in your rust_quickstart directory.

Run the following command to navigate into the project directory:

cd rust_quickstart
3

Add the following crates to your project by including them in the dependencies list located in your project's Cargo.toml file:

  • mongodb, the Rust driver crate

  • serde, the serialization crate

  • futures, an asynchronous runtime crate that provides core abstractions

Tip

The mongodb crate resolves the bson crate, which is the primary MongoDB data representation crate. You can omit the bson crate in your dependencies list.

The driver supports both asynchronous and synchronous runtimes. To see example dependency lists for each runtime, select from the following Asynchronous API and Synchronous API tabs:

[dependencies]
serde = "1.0.188"
futures = "0.3.28"
tokio = {version = "1.32.0", features = ["full"]}
[dependencies.mongodb]
version = "3.1.0"
[dependencies]
serde = "1.0.188"
[dependencies.mongodb]
version = "3.1.0"
features = ["sync"]

To learn more about asynchronous and synchronous runtimes, see the Asynchronous and Synchronous APIs guide.

After you complete these steps, you have Rust and Cargo installed and a new Rust project with the necessary driver dependencies.

Note

If you run into issues on this step, ask for help in the MongoDB Community Forums or submit feedback by using the Rate this page tab on the right or bottom right side of this page.

Back

Quick Start

Next

Create a MongoDB Deployment