MongoDB c++ 遗留驱动程序 1.1.2 不工作 - 使用 VS2013、Win 10 编译,boost-1_62

MongoDB c++ legacy driver 1.1.2 not working - Compiled with VS2013, Win 10, boost-1_62

驱动编译成功,没有问题。我编写了一个简单的程序来测试驱动程序。基本上以下是代码:

static std::vector<mongo::HostAndPort> hosts = { mongo::HostAndPort("xxxxxxxx-a0.mlab.com:xxxxx"), mongo::HostAndPort("xxxxxxxx-a1.mlab.com:xxxxx") };
static mongo::DBClientReplicaSet con("rs-xxxxxxxx", hosts, 0);


std::string errmsg;
mongo::client::initialize();
con.connect();
con.auth("dbname", "userid", "password", errmsg);

我编译代码没有问题。该 exe 无法以调试模式启动,给出错误 0xc000a200。我根本无法调试。在发布模式下,它会在启动时停止。我注意到控制台中有一个提升警告:

Assertion failed: px != 0, file C:\Boost\include\boost-1_62\boost/smart_ptr/scoped_ptr.hpp, line 105

并且有一个错误弹出窗口:

MongoDB C++ Legacy Driver Error

我能够选择调试,这里是程序停止的地方 - replica_set_monitor.cpp 的最后一行:

void ReplicaSetMonitor::createIfNeeded(const string& name, const set<HostAndPort>& servers) {
    LOG(3) << "ReplicaSetMonitor::createIfNeeded " << name;
    boost::lock_guard<boost::mutex> lk(setsLock);
    ReplicaSetMonitorPtr& m = sets[name];
    if (!m)
        m = boost::make_shared<ReplicaSetMonitor>(name, servers);
    // Don't need to hold the lifetime lock for safeGo as
    // 1) we assume the monitor is created as the contract of this class is such that initialize()
    //    must have been called.
    // 2) replicaSetMonitorWatcher synchronizes safeGo internally using the _monitorMutex
    replicaSetMonitorWatcher->safeGo();
}

请帮忙!非常感谢!

你需要调用 mongo::client::initialize before 你构造任何驱动程序对象,或 BSON 就此而言。将调用移至上面声明 DBClientReplicaSet 对象的 mongo::client::initialize