Navigation

MongoDB Rust Driver

On this page

  • Introduction
  • Installation
  • Connect to MongoDB Atlas
  • Connect to a MongoDB Server on Your Local Machine
  • Compatibility

This is the official MongoDB Rust Driver.

See Installation

Select from the Sync or Async tabs below for corresponding connection code samples.

To connect to a MongoDB Atlas cluster, use the Atlas connection string for your cluster:

Note

For information about connecting to Atlas Serverless, see the Serverless Instance Limitations page for the minimum driver version you need.

If you need to run a MongoDB server on your local machine for development purposes instead of using an Atlas cluster, you need to complete the following:

  1. Download the Community or Enterprise version of MongoDB Server.
  2. Install and configure MongoDB Server.
  3. Start the server.
Important

Always secure your MongoDB server from malicious attacks. See our Security Checklist for a list of security recommendations.

After you successfully start your MongoDB server, specify your connection string in your driver connection code.

If your MongoDB Server is running locally, you can use the connection string "mongodb://localhost:<port>" where <port> is the port number you configured your server to listen for incoming connections.

If you need to specify a different hostname or IP address, see our Server Manual entry on Connection Strings.

To test whether you can connect to your server, replace the connection string in the Connect to MongoDB Atlas code example and run it.

Note

The Rust driver is currently missing some features, which are noted below. We plan to make this driver consistent with our other drivers in the future.

Rust Driver Version
MongoDB 5.0
MongoDB 4.4
MongoDB 4.2
MongoDB 4.0
MongoDB 3.6
2.0
(*)
(*)
(*)
(*)
(*)
1.1
(*)
(*)
(*)
(*)
1.0
(*)
(*)
(*)
(*)

The Rust driver is not compatible with MongoDB server versions older than 3.6.

(*) Not all features in MongoDB are available in this version of the driver. Unsupported features include Change Streams, Causal Consistency, and Serverless Instance support.

The MongoDB Rust driver requires Rust 1.48 or later.

For more information on how to read the compatibility tables, see our guide on MongoDB Compatibility Tables.

Give Feedback

On this page

  • Introduction
  • Installation
  • Connect to MongoDB Atlas
  • Connect to a MongoDB Server on Your Local Machine
  • Compatibility