Docs Menu
Docs Home
/ / /
C++ Driver
/

Create a Driver Instance

On this page

  • Overview
  • Create a mongocxx::instance
  • API Documentation

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.

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:

#include <mongocxx/instance.hpp>
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.

To learn more about the mongocxx::instance class in the C++ driver, see the following API documentation:

  • mongocxx::instance

Back

Connect to MongoDB