使用mongocxx 3.3或mongo cxx3.4稳定版本,我正在尝试连接到mongo atlas实例。这是我的基本代码:
#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"];我已经测试了几种替代方法,比如使用客户端选项(比如这里解释的:http://mongocxx.org/mongocxx-v3/configuration/),以及设置pem文件路径(比如这里解释的:Mongocxx fails to connect to mongoDB with SSL )。
我总是会遇到以下错误:
terminate called after throwing an instance of 'mongocxx::v_noabi::exception'
what(): SSL support not available
Aborted (core dumped)发布于 2019-07-11 04:13:30
出现此错误的原因是C和C++驱动程序中的一个或两个都配置为不支持SSL。C++驱动程序构建缺省为SSL支持(查找MONGOCXX_ENABLE_SSL CMake选项)。因此,最可能的解释是底层C驱动程序是在没有SSL的情况下构建的,第二个最可能的解释是C驱动程序确实内置了SSL支持,但在构建C++驱动程序时将其显式设置为off。您可以通过在C驱动程序标头中查找MONGOC_ENABLE_SSL的值来验证C驱动程序的状态。如果启用了它,它应该如下所示:
$ 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当然,您应该将上述include目录的路径替换为安装C驱动程序的实际位置。
如果您在其中看到除#define MONGOC_ENABLE_SSL 1之外的任何内容,则说明您的C驱动程序没有启用SSL支持,您需要重新构建它才能启用。
https://stackoverflow.com/questions/56977425
复制相似问题