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.
Installation¶
See Installing the MongoDB C Driver (libmongoc) and BSON library (libbson).
Connect to MongoDB Atlas¶
To connect to a MongoDB Atlas cluster, use the Atlas connection string for your cluster:
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¶
C Driver Version | MongoDB 4.4 | MongoDB 4.2 | MongoDB 4.0 | MongoDB 3.6 | MongoDB 3.4 | MongoDB 3.2 | MongoDB 3.0 | MongoDB 2.6 |
---|---|---|---|---|---|---|---|---|
Version 1.17 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
Version 1.16 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
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¶
C Driver Versions | C11 | C99 | C89 |
---|---|---|---|
All Versions | ✓ | ✓ | ✓ |
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.
- File a bug or feature request on JIRA.
Give Feedback