(Re)Install MongoDB. Next, I wanted to do a clean install of MongoDB. I tried a handful of different options, but Brew was the most convenient. For those who have tried to follow older tutorials, mongodb has been removed from homebrew-core. Now, you’ll need to use mongo-community, which can be accessed as follows.
The mongocxx driver builds on top of the MongoDB C driver.
Unless you know that your package manager offers a high enough version, youwill need to download and build from the source code. Get a tarball fromthe C Driver releasespage.
Follow the instructions for building from a tarball atInstalling libmongoc.
Industry best practices and some regulations require the use of TLS 1.1or newer. The MongoDB C Driver supports TLS 1.1 on Linux if OpenSSL isat least version 1.0.1. On macOS and Windows, the C Driver uses nativeTLS implementations that support TLS 1.1.
The mongocxx driver uses the C++17 features
std::string_view. To compile the mongocxx driver for pre-C++17, youmust choose one of the following implementations for these features:
MNMLSTC/core (default for non-Windows platforms)Select with
-DBSONCXX_POLY_USE_MNMLSTC=1. NOTE: This optionvendors a header-only installation of MNMLSTC/core into the bsoncxxlibrary installation and will therefore download MLNMLSTC from GitHubduring the build process. If you already have an available version ofMNMLSTC on your system, you can avoid the download step by using
Boost (default for Windows platforms)Select with
-DBSONCXX_POLY_USE_BOOST=1. This is currently theonly option if you are using a version of MSVC that does not supportC++17.
-DBSONCXX_POLY_USE_STD_EXPERIMENTAL=1. If yourtoolchain’s standard library provides
string_view in the namespace
std::experimental, you can usethis option. Be aware that your standard library’s
std::experimental implementation may change over time,breaking binary compatibility in unexpected ways. Note that thispolyfill is not recommended and is unsupported.
Most users should be fine sticking with the default. However, if youhave an existing application which makes heavy use of one of theavailable libraries, you may prefer to build the mongocxx driveragainst the same library.
DO NOT change your project’s polyfill if you need to create astable binary interface.
The most reliable starting point for building the mongocxx driver is the latestrelease tarball.
The mongocxx releasespage will have links to the release tarball for the version you wish you install. Forexample, to download version 3.6.6:
Make sure you change to the
build directory of whatever source tree youobtain.
On Unix systems,
libmongoc installs into
/usr/local by default. Without additionalconfiguration,
mongocxx installs into its local build directory as a courtesy to those who buildfrom source. To configure
mongocxx for installation into
/usr/local as well, use the following
In the Unix examples that follow,
mongocxx is customized in these ways:
libmongocis found in
mongocxxis to be installed into
With those two distinct (arbitrary) install locations, a user would run this
Note If you need multiple paths in a CMake PATH variable, separate them with a semicolon likethis:
These options can be freely mixed with a C++17 polyfill option. For instance, this is how a userwould run the command above with the Boost polyfill option:
mongocxx3.1.x or 3.0.x
Instead of the
-DCMAKE_PREFIX_PATH option, users must specify the
libmongoc installationdirectory by using the
If you are using the default MNMLSTC polyfill and are installing to adirectory requiring root permissions, you should install the polyfill with
sudo before building the rest of mongocxx so you don’t have to runthe entire build with
Once MNMLSTC is installed, or if you are using a different polyfill,build and install the driver:
The driver can be uninstalled at a later time in one of two ways. First,the uninstall target can be called:
Second, the uninstall script can be called: