MongoDB C++ Driver
On this page
Introduction
Welcome to the documentation site for the official MongoDB C++ driver.
You can add the driver to your application to work with MongoDB using
the C++11 or later standard. Download the library, mongocxx
,
from mongocxx.org
or set up a runnable project by following our tutorial.
Installation
Connect to MongoDB Atlas
To connect to a MongoDB Atlas cluster, use the Atlas connection string for your cluster:
//... mongocxx::instance inst{}; // This should be done only once. mongocxx::client conn{ mongocxx::uri{ "mongodb+srv://<username>:<password>@<cluster-url>/test?retryWrites=true&w=majority" } }; mongocxx::database db = conn["test"];
Note
For information about connecting to Atlas Serverless, see the Serverless Instance Limitations page for the minimum driver version you need.
Connect to a MongoDB Server on Your Local Machine
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:
Download the Community or Enterprise version of MongoDB Server.
Install and configure MongoDB Server.
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.
Compatibility
MongoDB Compatibility
The following compatibility table specifies the recommended version(s) of the MongoDB C++ driver for use with a specific version of MongoDB.
The first column lists the driver version(s).
Compatibility Table Legend
Icon | Explanation |
---|---|
✓ | All features are supported. |
⊛ | The Driver version will work with the MongoDB version, but not all
new MongoDB features are supported. |
No mark | The Driver version is not tested with the MongoDB version. |
C++ Driver Version | MongoDB 6.0 | MongoDB 5.0 | MongoDB 4.4 | MongoDB 4.2 | MongoDB 4.0 | MongoDB 3.6 | MongoDB 3.4 | MongoDB 3.2 | MongoDB 3.0 | MongoDB 2.6 | MongoDB 2.4 |
---|---|---|---|---|---|---|---|---|---|---|---|
3.7 | ⊛ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
3.6 | ⊛ | ⊛ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
3.5 | ⊛ | ⊛ | ⊛ | ⊛ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
3.4 | ⊛ | ⊛ | ⊛ | ⊛ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
3.3 | ✓ | ✓ | ✓ | ✓ | |||||||
3.2 | ✓ | ✓ | ✓ | ✓ | ✓ | ||||||
3.1 | ✓ | ✓ | ✓ | ✓ | ✓ | ||||||
3.0 | ✓ | ✓ | ✓ | ✓ |
The driver does not support older versions of MongoDB.
Language Compatibility
The following compatibility table specifies the recommended version(s) of the MongoDB C++ driver for use with a specific version of C++.
The first column lists the driver version(s).
C++ Driver Version | C++17 | C++14 | C++11 | C++03 |
---|---|---|---|---|
3.x | ✓ | ✓ | ✓ | |
1.x | ✓ | ✓ | ✓ |
For more information on how to read the compatibility tables, see our guide on MongoDB Compatibility Tables.
How to get help
Ask questions on our MongoDB Community Forums.
Visit our Support Channels.
See how to report a bug.