Using mongo-cxx-driver from the rh-mongodb32 Software Collection

Updated

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.

  1. Install the rh-mongodb32-mongo-cxx-driver package and the -devel packages for rh-mongodb32-mongo-cxx-driver and rh-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
    
  2. 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
    
  3. mongo-cxx-driver from the rh-mongodb32 Software Collection is now installed into an alternate path, so the rh-mongodb32 Collection has to be enabled during the build:

    ~]# scl enable rh-mongodb32 -- c++ -o simple_client_demo -lmongoclient -lboost_system simple_client_demo.cpp
    
  4. The resulted application requires libraries from the rh-mongodb32 Software Collection, which means that to run the simple_client_demo application, the rh-mongodb32 Collection has to be enabled. Also note that this example program requires a running mongod server on localhost to 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"
    
Article Type