You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MongoCXX驱动通过SOCKS5代理连接MongoDB Atlas失败的问题求助

MongoCXX驱动通过SOCKS5代理连接MongoDB Atlas失败的问题求助

大家好,我最近在尝试通过一台装有SOCKS5代理的服务器,使用MongoCXX驱动连接MongoDB Atlas时遇到了问题,想在这里求助一下。

问题背景

我已经能通过mongosh工具,在连接串中指定proxyHost和proxyPort参数,成功通过SOCKS5代理连接到MongoDB Atlas并正常操作。但当我用C++代码使用相同的连接串配置时,却始终无法成功建立有效连接。

我的C++连接代码

std::string suri = "mongodb+srv://<user>:<password>@<atlas_host>?&replicaSet=<replica_set>&proxyHost=<host>&proxyPort=8081";
const auto uri = mongocxx::uri{ suri };

mongocxx::options::client clientOptions;
if (uri.tls()) {
    mongocxx::options::tls tlsOptions;
    tlsOptions.allow_invalid_certificates(true);
    clientOptions.tls_opts(tlsOptions);
}

mongocxx::client cl{ uri, clientOptions };

遇到的错误信息

当我尝试对数据库进行读写操作时,立刻抛出了如下超时错误:

0x7fffffffbab8 "No suitable servers found (serverSelectionTryOnce set): [socket timeout calling hello on '<shard_0>:27017'] [socket timeout calling hello on '<shard_1>:27017'] [socket timeout calling hello on '<shard_2>:27017']. Topology type: Unknown"

我的怀疑与疑问

我查阅了MongoCXX驱动的官方文档后,开始怀疑驱动本身并不支持在连接串中配置代理相关参数。如果确实是驱动不支持SOCKS5代理的话,有没有其他替代方案能让我的C++程序与MongoDB Atlas的通信通过SOCKS5代理进行呢?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 08:54:37