1

When I try to run the code below :

     int main(int,char**){
     mongocxx::instance inst{};
     mongocxx::client conn{mongocxx::uri{"mongodb://localhost:27019"}};
     auto db = conn["test"];
  {
     auto cursor = db["restaurants"].find({});
     for (auto&& doc : cursor) {
        std::cout << bsoncxx::to_json(doc) << std::endl;
    }
     getchar();
     return 0;      
   }

it works well in debug build,but crashed in the release build, i have rebuild the mongo-cxx-driver several times,and it didn't worked too. i have tried the ideas as

Why is there an access violation on connecting to MongoDB from C++?
Mongodb cxx + Unreal Engine 4 - Crash while iterating over Cursor
 Mongodb Cxx Driver Test crashing in Release Build [ Works fine in Debug ]
mentioned,Unfortunately, it is still not working properly. so can someone give me some advices to slove this problems?

Esteem it a favor

wm.Guo
  • 11
  • 3
  • 1
    Very often these sort of issues are due to building some components against one set of C++ runtime libraries, and other components against different runtime libraries. The runtime library in use must match across the components, or these sorts of crashes are very common. In particular, ensure that your application, any third-party C++ libraries, and mongocxx are all built consistently wr.t. Debug vs Retail and Static vs Dynamic. – acm Sep 18 '17 at 21:46
  • hello,i have build the runtime libraries as the official documents guides,also i have tried the different versions of boost,mongocxx,libmongoc drivers,and so far, no one has to work properly in release build but works well in debug build. – wm.Guo Sep 19 '17 at 01:28
  • All of those things that you named need to be built the same way, but *so does your application*. – acm Sep 19 '17 at 23:04
  • My application is just to test to connect the mongodb database and get the documents in the db use vs2015,when i tested it in debug build to get the documents it works well.I am using the Mongo-C driver (1.7.0),Mongo-cxx-driver(3.1.3),and the Boost(1_65_1) – wm.Guo Sep 20 '17 at 10:27
  • Did you build *two versions* of the C++ driver? One in release mode and the other in debug mode? Because otherwise you are mixing the runtime libraries. You need to link a Debug build version of your application to Debug build versions of the drivers, and a Release build version of your application to Release build versions of the drivers. Are you doing that? Because if not you are mixing the runtime libraries. – acm Sep 20 '17 at 12:42

0 Answers0