Navigation

MongoDB C Driver

Introduction

The MongoDB C Driver, also known as “libmongoc”, is the official client library for C applications, and provides a base for MongoDB drivers in higher-level languages.

The library is compatible with all major platforms. It depends on libbson to create and parse BSON data.

Connect to MongoDB Atlas

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

#include <mongoc/mongoc.h>

int
main (int argc, char *argv[])
{
   mongoc_database_t *database;
   mongoc_client_t *client;

   mongoc_init ();

   client = mongoc_client_new(
      "mongodb+srv://<username>:<password>@<cluster-url>/test?retryWrites=true&w=majority"
   );
   database = mongoc_client_get_database (client, "test");

   mongoc_database_destroy (database);
   mongoc_client_destroy (client);

   mongoc_cleanup ();

   return 0;
}

See Advanced Connections for more ways to connect.

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.2 MongoDB 4.0 MongoDB 3.6 MongoDB 3.4 MongoDB 3.2 MongoDB 3.0 MongoDB 2.6
Version 1.15  
Version 1.14    
Version 1.13    
Version 1.12    
Version 1.11    
Version 1.10      
Version 1.9    
Version 1.8      
Version 1.7      
Version 1.6      
Version 1.5      
Version 1.4        
Version 1.3        
Version 1.2          
Version 1.1          
Version 1.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 Versions C11 C99 C89
All Versions

How to get help