Not working - Legacy C++ Driver 1.1.2 Compiled with VS 2013 on Windows 10 with boost boost-1_62

45 views
Skip to first unread message

Harold Zhao

unread,
Oct 19, 2016, 7:15:07 PM10/19/16
to mongodb-user
Hi everyone,

I am having a hard time working with the driver. The driver compiled successfully without problem. Boost was compiled on my system too.

I coded a very simple test program to test it and I am getting errors:

Basically the following is the code:


static std::vector<mongo::HostAndPort> hosts = { mongo::HostAndPort("xxxxxxx0.mlab.com:19615"), mongo::HostAndPort("xxxxxxx1.mlab.com:19615") };
static mongo::DBClientReplicaSet replicaset(xxxxx019615", hosts, 0);


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


In debug mode, it showed error 0xc000a200 and was not able to debug at all since the program just won't start.

In release mode, it will stop working at starting up. 

Firstly, I noticed there is a boost warning:

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

Then I was able to choose to debug and here is the error:



When I broke the execution, I noticed the program stopped at replica_set_monitor.cpp (driver file) on the last line. Here is the part of the code:

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();
}

I didn't do anything in my test program except loading the driver and try to do a query. Apparently, the driver didn't work so I was not able to test anything.

Please help!

Thanks!



Harold Zhao

unread,
Oct 19, 2016, 7:29:43 PM10/19/16
to mongodb-user
Got reply from mongoDB tech support:

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.

And the answer is correct. But now I am getting exception when trying to authenticate at:

replicaset.auth("databasename", "userid", "password", errmsg);

"Unhandled exception at 0x00007FFD87F77788 in mongodrivertest.exe: Microsoft C++ exception: mongo::UserException at memory location 0x00000056C6FFF070".

Program broke at: 'bool DBClientWithCommands::auth(...... << username << saslCommandPasswordFieldName << password_text << saslCommandDigestPasswordFieldName << digestPassword));` 

What happened?

Rassi

unread,
Oct 20, 2016, 11:28:04 AM10/20/16
to mongodb-user
It looks like an exception was thrown during your call to DBClientWithCommands::auth().  You should generally expect most API calls in the legacy driver to possibly throw a DBException (UserException is a derived class of DBException), and should thus include exception handling logic in your program.  See assert_util.h for details.

All DBException objects include a code and a message, detailing why the exception is thrown.  In order to diagnose this issue further, please replace your call to DBClientWithCommands::auth(...) with the following try/catch block, and reply to this thread with the relevant output your program generates:

    try {
        DBClientWithCommands::auth(...);
    } catch (const mongo::DBException& ex) {
        std::cerr << "Caught mongo::DBException: " << ex.toString() << std::endl;
        throw;
    }

Also, are you starting a new project using the MongoDB C++ driver?  If so, you may want to consider using mongocxx (versions 3.x and above of the C++ driver), which features an improved API over the legacy driver (versions 1.x of the C++ driver).  See the driver documentation for further information.

~ Rassi

On Wednesday, October 19, 2016 at 7:29:43 PM UTC-4, Harold Zhao wrote:
Got reply from mongoDB tech support:

Harold X. Zhao

unread,
Oct 20, 2016, 4:51:50 PM10/20/16
to mongod...@googlegroups.com
Thanks, Rassi!

Yes, I did do that and figured out it's because the driver was not compiled with ssl. Currently working on building mongoDB drivers with ssl. Installing OpenSSL is a nightmare. So many different sources, all with different errors. There changed the build method for the latest 1.1.0 version. Looks simpler but all with errors. Research and try and research and try. I am finally close to success in building the latest OpenSSL 1.1.0 on my computer.

I will share how-to if someone runs into problem in doing this.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/70cd06b7-7355-4fce-8a79-5ef1c98091ca%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages