Mongocxx连接池(VS发行版)在连接到远程服务器时出现问题

时间:2018-05-18 01:11:09

标签: mongodb visual-studio visual-c++ mongo-cxx-driver vcpkg

我已安装(现在已经使用了一段时间)mongocxx驱动程序通过vcpkg并且所有内容都正确安装并在Debug版本中运行完美(我使用Visual Studio 2017而我的应用程序是Windows表单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插入不会出现问题。每次工作10分钟。根据我观察到的情况,它只是错过/跳过一些条目(大多数是在成功尝试之后)。

随着远程计算机中加载的发布版本,我无法进行任何调试,即使我运行的调试版本也能以较短的间隔运行(每个1分钟)。

0 个答案:

没有答案