Using mongo-cxx-driver from the rh-mongodb32 Software Collection
The rh-mongodb32 Software Collection shipped in Red Hat Software Collections (RHSCL) 2.3 includes the mongo-cxx-driver subpackage. At the time of the RHSCL 2.3 release, it was the latest release of the Content from mongodb.github.io is not included.legacy version branch.
Limitations
The mongo-cxx-driver driver has a limitation regarding the used C++ standards by design:
If you are building the C++ driver with C++11 enabled, you must build your application with C++11 enabled as well - see the Content from mongodb.github.io is not included.upstream documentation.
rh-mongodb32-mongo-cxx-driver is built without C++11 enabled, so applications have to be build with the C++11 standard disabled as well.
Note: This limitation applies also to C++ standards later than C++11.
Example
This article demonstrates building of the Content from raw.githubusercontent.com is not included.simple_client_demo C++ application using the mongo-cxx-driver driver from RHSCL. To get more example applications, see the Content from github.com is not included.mongo-cxx-driver upstream GitHub page.
Prerequisite: The host machine has to have a C++ compiler installed.
-
Install the
rh-mongodb32-mongo-cxx-driverpackage and the-develpackages forrh-mongodb32-mongo-cxx-driverandrh-mongodb32-boost. Note that the RHSCL repository has to be enabled:~]# sudo yum-config-manager --enable rhel-server-rhscl-7-rpms ~]# sudo yum install rh-mongodb32-mongo-cxx-driver rh-mongodb32-mongo-cxx-driver-devel rh-mongodb32-boost-devel -
Prepare the source code of the application:
~]# curl https://raw.githubusercontent.com/mongodb/mongo-cxx-driver/legacy/src/mongo/client/examples/simple_client_demo.cpp > simple_client_demo.cpp -
mongo-cxx-driverfrom therh-mongodb32Software Collection is now installed into an alternate path, so therh-mongodb32Collection has to be enabled during the build:~]# scl enable rh-mongodb32 -- c++ -o simple_client_demo -lmongoclient -lboost_system simple_client_demo.cpp -
The resulted application requires libraries from the
rh-mongodb32Software Collection, which means that to run thesimple_client_demoapplication, therh-mongodb32Collection has to be enabled. Also note that this example program requires a runningmongodserver onlocalhostto exit successfully:~]# sudo yum install rh-mongodb32-mongodb-server ~]# sudo service rh-mongodb32-mongod start ~]# scl enable rh-mongodb32 -- ./simple_client_demo "mongodb://localhost:27017"