Reputation: 53
Driver compiled successfully without problem. I coded a simple program to test the driver. Basically the following is the code:
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);
I compiled the code with no problem. The exe couldn't start in bebug mode, giving error 0xc000a200. I was not able to debug at all. In release mode, it stopped right at starting-up. I noticed there was a boost warning in the console:
Assertion failed: px != 0, file C:\Boost\include\boost-1_62\boost/smart_ptr/scoped_ptr.hpp, line 105
And there was an error popup:
MongoDB C++ Legacy Driver Error
I was able to choose debug and here is where the program stopped - the last line of 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();
}
Please help! Thanks a lot!
Upvotes: 1
Views: 161
Reputation: 12727
You need to call mongo::client::initialize
before you construct any driver objects, or BSON for that matter. Move the call to mongo::client::initialize
above where you declare the DBClientReplicaSet object.
Upvotes: 1