.. _c-language-center:

.. include:: /includes/unicode-checkmark.rst

================
MongoDB C Driver
================

.. default-domain:: mongodb

.. contents:: On this page
   :local:
   :backlinks: none
   :depth: 1
   :class: twocols

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.

- `Tutorial <http://mongoc.org/libmongoc/current/tutorial.html>`__

- `Usage Guide <http://mongoc.org/libmongoc/current/index.html>`__

- `API Reference <http://mongoc.org/libmongoc/current/api.html>`_

- `Changelog <https://github.com/mongodb/mongo-c-driver/releases>`__

- `Source Code <https://github.com/mongodb/mongo-c-driver>`__


Installation
------------

See `Installing the MongoDB C Driver (libmongoc) and BSON library (libbson)
<http://mongoc.org/libmongoc/current/installing.html>`__.


Connect to MongoDB Atlas
------------------------

.. include:: /includes/atlas-connect-blurb.rst

.. code-block:: c

   #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 <http://mongoc.org/libmongoc/current/advanced-connections.html>`__
for more ways to connect.


Compatibility
-------------

MongoDB Compatibility
~~~~~~~~~~~~~~~~~~~~~

.. include:: /includes/extracts/c-driver-compatibility-matrix-mongodb.rst

.. include:: /includes/mongodb-compatibility-table-c.rst

.. include:: /includes/older-server-versions-unsupported.rst

Language Compatibility
~~~~~~~~~~~~~~~~~~~~~~

.. include:: /includes/extracts/c-driver-compatibility-matrix-language.rst

.. include:: /includes/language-compatibility-table-c.rst

.. include:: /includes/help-links-c.rst
