C++ Mongodb driver, not working

471 views Asked by At

I'am having problems using c++ mongo db driver. I downloaded the "legacy" branch and built it myself dynamically with /MD switch, using vc12.0. I'am trying to connect to my database and retrieve some fields from the collection, but getting the weird exception. I'm using QT 5.4, The code is:

auto status = mongo::client::initialize();
std::string errmsg;
if(status.isOK())
{
try
{
    mongo::HostAndPort serv("127.0.0.1:27017");

    c.connect(serv,errmsg);
}
catch( const mongo::DBException &e ) {
    QString qstr(e.what());
    qDebug() << "caught " << qstr;
  }

mongo::Query query = mongo::Query("{'name':''}");
auto test = c.findOne("database.clients",query);
}

On the findone line I get the exception: Errorshttp://rghost.ru/7PsTG9Sxc/image.png

What is the right way to execute find/findone queries in c++ driver? And, please give me work samples for another mongo driver functions, how properly run it on c++.

UPDATE

Stack Trace Screenshot of the exception: enter image description here

I guees it is some problem with std::string?

UPDATE 2

Ok, i made a RELEASE build in qt creator, and mongo driver works fine with my programm release build. It seems that my program /MDd conflicts with /MD mongodriver. However, i wanted to compile mongodb driver with /MDd so i can use debugger, but! When i build the driver with dbg=on, i get only one library: libmongoclient-gd.lib. No dlls, no "lubmongoclient" debug built, like whats with this driver? Is it even possible to build it with /MDd

0

There are 0 answers