Navigation

MongoDB C++ Driver

Introduction

The MongoDB C++ Driver is the official client library for C++ applications using the C++11 (or later) standard.

Connect to MongoDB Atlas

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

#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>

//...

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"];

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).

C++ Driver Version MongoDB 4.0 MongoDB 3.6 MongoDB 3.4 MongoDB 3.2 MongoDB 3.0 MongoDB 2.6 MongoDB 2.4
mongocxx 3.4.x    
mongocxx 3.3.x      
mongocxx 3.2.x    
mongocxx 3.1.x    
mongocxx-3.0.x      

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++03 C++11 C++14
mongocxx-3.x  
legacy-1.x

How to get help