0

我已经通过 vcpkg 安装(并且已经使用了一段时间)mongocxx 驱动程序,并且所有内容都正确安装并在调试版本中完美运行(我使用的是 Visual Studio 2017,我的应用程序是 Windows Form c++(CLR)应用程序) . 在我的应用程序中,每次我在服务器上上传一些数据时,我都会获得一个连接池并获取一个客户端。我的自动数据上传的典型间隔是 10 分钟。我的设置是

// 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). . .

问题是,数据库文档每 10 分钟上传一次,在 Debug 版本中没有问题,但是对于 Release 版本(当我加载我的应用程序的 Release 版本并开始使用它时),mongo insert 每次 10 分钟都不起作用. 它只是错过/跳过了一些条目(根据我的观察,主要是在成功尝试后的一个)。

使用远程计算机中加载的发布版本,即使我运行了调试版本,它也可以在更短的时间间隔内完美运行(例如每个 1 分钟),但我无法进行任何调试。

4

0 回答 0