Search code examples
c++mongodbsslmongo-cxx-driver

Error connecting mongocxx to mongodb server: SSL support not available


Using mongocxx 3.3 or mongo cxx 3.4 stable versions, I´m trying to connect to a mongo atlas instance. This is my basic code:

#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>

mongocxx::instance inst{};    
mongocxx::uri uri = mongocxx::uri("mongodb+srv://...");
mongocxx::client conn(uri);
mongocxx::database db = conn["test"];

And I have tested several alternatives, like using client options (like explained here: http://mongocxx.org/mongocxx-v3/configuration/), and also setting a pem file path like explained here: Mongocxx fails to connect to mongoDB with SSL.

I always have the following error:

terminate called after throwing an instance of 'mongocxx::v_noabi::exception'
what():  SSL support not available
Aborted (core dumped)

Solution

  • You got this error because one or both of the C and C++ drivers was configured without SSL support. The C++ driver build defaults to SSL support (look for the MONGOCXX_ENABLE_SSL CMake option). So the most likely explanation is that the underlying C driver was built without SSL, and the second most likely explanation is that the C driver does have SSL support built in, but it was explicitly set to off when building the C++ driver. You can verify the state of the C driver by looking for the value of MONGOC_ENABLE_SSL in the C driver headers. If it is enabled, it should look like this:

    $ find /usr/local/Cellar/mongo-c-driver/1.14.0/include -type f -name "*.h" | xargs grep 'MONGOC_ENABLE_SSL '
    /usr/local/Cellar/mongo-c-driver/1.14.0/include/libmongoc-1.0/mongoc/mongoc-config.h: * MONGOC_ENABLE_SSL is set from configure to determine if we are
    /usr/local/Cellar/mongo-c-driver/1.14.0/include/libmongoc-1.0/mongoc/mongoc-config.h:#define MONGOC_ENABLE_SSL 1
    /usr/local/Cellar/mongo-c-driver/1.14.0/include/libmongoc-1.0/mongoc/mongoc-config.h:#if MONGOC_ENABLE_SSL != 1
    

    Of course, you should replace the path to the include directory above with the actual location where you have the C driver installed.

    If you see anything other than #define MONGOC_ENABLE_SSL 1 in there, then your C driver doesn't have SSL support enabled and you will need to rebuild it to have it.