Initialization and cleanup#

Synopsis#

Initialize the MongoDB C Driver by calling mongoc_init() exactly once at the beginning of your program. It is responsible for initializing global state such as process counters, SSL, and threading primitives.

Exception to this is mongoc_log_set_handler(), which should be called before mongoc_init() or some log traces would not use your log handling function. See Custom Log Handlers for a detailed example.

Call mongoc_cleanup() exactly once at the end of your program to release all memory and other resources allocated by the driver. You must not call any other MongoDB C Driver functions after mongoc_cleanup(). Note that mongoc_init() does not reinitialize the driver after mongoc_cleanup().

Changed in version 2.0.0: Versions prior to 2.0.0 supported a non-portable automatic initialization and cleanup with the CMake option ENABLE_AUTOMATIC_INIT_AND_CLEANUP. This was removed in 2.0.0. Ensure your application call mongoc_init() and mongoc_cleanup().