将mongocxx连接到mongodb服务器时出错:SSL支持不可用
Error connecting mongocxx to mongodb server: SSL support not available
使用 mongocxx 3.3 或 mongo cxx 3.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无法使用SSL连接到mongoDB。
我总是有以下错误:
terminate called after throwing an instance of 'mongocxx::v_noabi::exception'
what(): SSL support not available
Aborted (core dumped)
您收到此错误是因为一个或两个 C 和 C++ 驱动程序是在没有 SSL 支持的情况下配置的。C++驱动程序版本默认为 SSL 支持(查找 MONGOCXX_ENABLE_SSL
CMake 选项(。因此,最可能的解释是底层 C 驱动程序是在没有 SSL 的情况下构建的,第二个最可能的解释是 C 驱动程序确实内置了 SSL 支持,但在构建 C++ 驱动程序时显式设置为关闭。可以通过在 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
当然,您应该将上面包含目录的路径替换为安装 C 驱动程序的实际位置。
如果您看到除#define MONGOC_ENABLE_SSL 1
以外的任何内容,则您的 C 驱动程序未启用 SSL 支持,您需要重新生成它才能获得它。
相关文章:
- 编译时未启用intel oneApi CUDA支持
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 使用CMake检测支持的C++标准
- 为什么istream不支持右值提取
- SSL上的`curl_easy_send`和`curl_asy_recv`:如何处理`CURLE_AGAIN`
- 当我编译webrtc服务器时,Windows上只支持clang-cl
- 扩展光电二极管探测器以支持多个传感器
- MSVC是否支持C++11样式的属性而不是__declspec
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 当使用比格式支持的精度更高的精度来显示数字时,会写出什么数据
- 错误:(-210:不支持的格式或格式组合)功能'create'中的硬件视频解码器不支持视频源
- 使用 OpenSSL 从内存中读取原始 SSL/TLS 证书
- 哪个C++规范开始支持 std::vector
- 如何检测VS C++编译器是否支持C++11?
- Mongocxx无法使用SSL连接到mongoDB
- 如何使用MinGW编译器和SSL支持静态编译Qt
- 将mongocxx连接到mongodb服务器时出错:SSL支持不可用
- BSD许可证c/c++库可以用来实现http客户端支持http1.1和ssl
- QT https SSL支持静态QT静态程序构建 - 仍然需要openssl dll
- QT https SSL支持静态QT静态程序构建 - 获取“协议”https“未知”