0

I've installed (and have been using it for a while now) mongocxx driver via vcpkg and everything installed correctly and runs perfectly in Debug version (I'm using Visual Studio 2017 and my application is a Windows Form c++ (CLR) application). In my application, I get a connection pool and acquire a client everytime I upload some data on the server. Typical interval of my automatic data upload is 10 minutes. My settings are

// Create pool (once)
mongocxx::uri uri_remote{ "mongodb://user:pwd@remote-host:PORT/database-name?minPoolSize=2&maxPoolSize=5" }; 
    mongocxx::pool pool_remote{ uri_remote }; 
    // The code below runs as a scheduled process after every 10 minutes
    auto client_remote = pool_remote.acquire(); 
    // The client is returned to the pool when it goes out of scope. 
    auto collection_remote = (*client_remote)["database-name"]["collection-1-name"]; 
    auto collection_st_remote = (*client_remote)["database-name"]["collection-2-name"]; 
    bsoncxx::document::value doc1= document
                << std::string(keys[0]) << entries[0] // A short string (device identifier)
                << std::string(keys[1]) << entries[1] // A short string location
                << std::string(keys[2]) << bsoncxx::types::b_date(std::chrono::system_clock::now()) // Current insert time
                << std::string(keys[3]) << entries[2] // String: updated entry name
                << std::string(keys[4]) << entries[3] // String: Updated entry description
                << std::string(keys[5]) << <float number>
                << std::string(keys[6]) << <integer>
                << finalize;
            // Below are the statuses I'm recording. A binary array (length = 7)
            bsoncxx::document::value doc2= document
                << std::string(status_keys[0]) << statuses[0]
                << std::string(status_keys[1]) << statuses[1]
                << std::string(status_keys[2]) << statuses[2]
                << std::string(status_keys[3]) << statuses[3]
                << std::string(status_keys[4]) << bsoncxx::types::b_date(std::chrono::system_clock::now())
                << std::string(status_keys[5]) << statuses[4] // Device identifier
                << std::string(status_keys[6]) << statuses[5]
                << finalize;
    // And finally insert 
    try { 
        // Insert remote. lines of code for doc1 and doc2 are skipped 
        collection_remote.insert_one(doc1.view()); 
        collection_st_remote.insert_one(doc2.view()); 
        // I'm skipping the rest of the code section here (just a catch statement after this). . .

The problem, the database documents get uploaded every 10 minutes without a problem in Debug version, but with the Release version (when I loaded the Release version of my application and started using that), the mongo insert doesn't work every time 10 minutes. It just misses/skips some entries (mostly one after a successful attempt according to what I observed).

With the release version loaded in a remote computer I'm unable to do any debugging even though I ran debug version which works perfectly with shorter intervals too (like 1 minute each).

halfer
  • 19,824
  • 17
  • 99
  • 186
Bilal
  • 43
  • 1
  • 11
  • I don't see what connection pools have to do with this other than that you probably should not have messed around with the defaults to begin with. You're actual problem is more likely in code that you are not showing here. We also may be missing a lot of context, but the operations presented and "every 10 minutes" seems very trivial for a C++ implementation and would probably be more suited to a different language implementation where you don't need to "mess around" at such a low level implementation. This "looks like" you presumed some existing code might "run faster" if you used C++. – Neil Lunn May 18 '18 at 01:20
  • You can try giving some more context to what things are actually doing, i.e "where doc1 and doc2 even come from", but there generally is not enough information ( or the exact listing ) to debug in a general way. See [How to Create a Minimal Complete and Verifiable Example](https://stackoverflow.com/help/mcve), where it may even be the case that your issue is even better "demonstrated" in a higher level language implementation. But unless there is something to reproduce, then there's not likely a solution to be found here. – Neil Lunn May 18 '18 at 01:23
  • Thanks Neil and apologies for not providing enough information. I added doc1 and doc2 in the code. doc1 and doc2 are just filled with some new values after collecting them at the time the above code runs (every 10 minutes). They mostly have short strings and binary number (0's and 1's). I have two versions of the same code running in Debug mode and one in Release mode. The Debug mode (with the same code) make connection fine but the Release version skips one and does it every 20 minutes instead. I chose c++ because the device I'm using had the SDK available only in c++ at that time – Bilal May 18 '18 at 04:04
  • I restarted Release version with 1 minute gap for 6 consecutive mins and it worked (all 6 entries were recorded in the remote database without a problem). I'm feeling certain it's somewhere in the code (other than the app). I forgot to mention that on the web server (it's a Nodejs application), I recently wrote another chunk of code to collect (some other real time readings) via the TCP connection and store them in the same MongoDB every 5 minutes. I'm wondering if that caused the problem but if yes then does that mean mongodb doesn't allow me to open that many concurrent connections? – Bilal May 18 '18 at 04:11
  • Finally, the readings that are collected via the TCP connection from the same device seem to not drop at all and that all the entries are stored correctly, while on the local app, the Release version (when run at 10 minutes interval) skips an entry for some reason? I'm trying to dig out more and hoping that it is a code mistake I'm making somewhere instead of any other major fault – Bilal May 18 '18 at 04:13

0 Answers0