Loading...
Searching...
No Matches
mongocxx::v1::instance Class Reference

`#include <mongocxx/v1/instance.hpp>`

## Description

An instance of the MongoDB C++ Driver.

All mongocxx API MUST be used within the lifetime of the instance object, with special exemptions listed below. Only ONE instance object may exist for the lifetime of a given process. It is undefined behavior to use the mongocxx API before the instance object is initialized or after the instance object is destroyed. It is undefined behavior to create more than one instance object.

int main() {
// ...
// MUST NOT call mongocxx API before this point.
{
mongocxx::v1::instance instance;
// MAY call mongocxx API at this point.
// ...
}
// MUST NOT call mongocxx API after this point.
// ...
}
mongocxx::v1::instance
An instance of the MongoDB C++ Driver.
Definition instance.hpp:64
mongocxx::v1::instance::instance
instance(instance &&)=delete
This class is not moveable.

Special exemptions
  Only the following API are permitted to be used outside the lifetime of an instance object:
  - mongocxx::v1::logger
  - mongocxx::v1::default_logger

See also
  - Initialization and Cleanup (mongoc)

## Public Types

enum class | errc
| Errors codes which may be returned by mongocxx::v1::instance. More...

## Public Member Functions

| instance ()
| Initialize the mongoc library with unstructured log messages disabled.
| instance (instance &&)=delete
| This class is not moveable.
| instance (instance const &)=delete
| This class is not copyable.
| instance (std::unique_ptr< v1::logger > handler)
| Initialize the mongoc library with the custom unstructured log message handler.
| instance (v1::default_logger tag)
| Initialize the mongoc library with its default unstructured log handler.
| ~instance ()
| Cleanup the mongocxx (and mongoc) library.
instance & | operator= (instance &&)=delete
| This class is not moveable.
instance & | operator= (instance const &)=delete
| This class is not copyable.

## Static Public Member Functions

static std::error_category const & | error_category ()
| The error category for mongocxx::v1::instance::errc.

## Friends

std::error_code | make_error_code (errc v)
| Support implicit conversion to std::error_code.

## Member Enumeration Documentation

## errc

enum class mongocxx::v1::instance::errc

strong

Errors codes which may be returned by mongocxx::v1::instance.

Enumerator
zero | Zero.
multiple_instances | Cannot construct multiple instance objects in a given process.

## Constructor & Destructor Documentation

## ~instance()

mongocxx::v1::instance::~instance | ( |  | ) |

Cleanup the mongocxx (and mongoc) library.

Calls mongoc_cleanup().

## instance() [1/5]

mongocxx::v1::instance::instance | ( | instance && |  | ) |

delete

This class is not moveable.

## instance() [2/5]

mongocxx::v1::instance::instance | ( | instance const & |  | ) |

delete

This class is not copyable.

## instance() [3/5]

mongocxx::v1::instance::instance | ( |  | ) |

Initialize the mongoc library with unstructured log messages disabled.

Calls mongoc_init() after disabling unstructured log messages by calling mongoc_log_set_handler(nullptr, nullptr).

Important
  To use mongoc's default log message handler, construct this object with instance(v1::default_logger tag) instead.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::instance::errc::multiple_instances if an instance object has already been created.

See also
  - Custom Log Handlers (mongoc)

## instance() [4/5]

mongocxx::v1::instance::instance | ( | std::unique_ptr< v1::logger > | handler | ) |

explicit

Initialize the mongoc library with the custom unstructured log message handler.

Calls mongoc_init after registering the custom unstructured log handler by calling mongoc_log_set_handler().

Parameters

  handler | Disable unstructured logging when null.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::instance::errc::multiple_instances if an instance object has already been created.

See also
  - Custom Log Handlers (mongoc)

## instance() [5/5]

mongocxx::v1::instance::instance | ( | v1::default_logger | tag | ) |

explicit

Initialize the mongoc library with its default unstructured log handler.

Calls mongoc_init without registering any custom unstructured log handler.

Parameters

  tag | Unused: only for overload resolution.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::instance::errc::multiple_instances if an instance object has already been created.

## Member Function Documentation

## error_category()

std::error_category const & mongocxx::v1::instance::error_category | ( |  | ) |

static

The error category for mongocxx::v1::instance::errc.

## operator=() [1/2]

instance & mongocxx::v1::instance::operator= | ( | instance && |  | ) |

delete

This class is not moveable.

## operator=() [2/2]

instance & mongocxx::v1::instance::operator= | ( | instance const & |  | ) |

delete

This class is not copyable.

## Friends And Related Symbol Documentation

## make_error_code

std::error_code make_error_code | ( | errc | v | ) |

friend

Support implicit conversion to std::error_code.

The documentation for this class was generated from the following file:

- mongocxx/v1/instance.hpp