Create a Driver Instance
Overview
To use the C++ driver, you must first create an instance of the mongocxx::instance
class. This instance performs the following functions in your application:
Initializes and shuts down the C++ driver
Initializes driver dependencies
Ensures the driver functions correctly
Manages the lifetimes of resources that are shared among
mongocxx::client
objects, such as the connection pool and BSON library
This guide shows you how to create a mongocxx::instance
object.
Create a mongocxx::instance
To create a mongocxx::instance
object, include the
mongocxx/instance.hpp
header file in your application. Then,
construct an instance of mongocxx::instance
at the start of your application,
as shown in the following example:
int main() { mongocxx::instance instance; }
Important
You must create a mongocxx::instance
object before you use the
C++ driver, and this object must remain
alive for as long as any other MongoDB objects are in scope.
API Documentation
To learn more about the mongocxx::instance
class in the C++ driver,
see the following API documentation: