繁体   English   中英

Mongodb C ++驱动程序,清理失败

[英]Mongodb C++ driver, failure at cleanup

我有一个小程序,尝试连接到mongodb并检查如果我希望接收对象会接收多少对象。 在这种情况下,我什至无法获得对象的数量,即使我只进行连接,我也会在清除过程中遇到错误。

我正在使用GlobalInstance对象维护我的连接并在退出时为我清理。 我从main调用此函数。 该程序实际上还没有执行任何其他操作。

关于我的段错误,我有什么建议吗? 大概这与无法调用connection-> count()有关?

非常感谢您的指导。

int foo() {
mongo::client::Options options;
options.setSSLMode(mongo::client::Options::kSSLRequired);
mongo::client::GlobalInstance mongo_connection(options);
mongo::DBClientBase* connection;
if (!mongo_connection.status().isOK()) {
    cout << "Mongo connection not established: "
     << mongo_connection.status() << endl;
}
try {
    mongo::DBClientConnection c(true);
    string error;
    ostringstream mongo_url;
    mongo_url << "mongodb://" << db_username << ":" << db_password << "@"
          << db_host << ":" << db_port << "/" << db_name;
    const mongo::ConnectionString conn_string =
    mongo::ConnectionString::parse(mongo_url.str(), error);
    if (!conn_string.isValid()) {
    cout << "Bad connection string: " << error << endl;
    }
    // Reality check.  Passes.
    cout << "user=" << conn_string.getUser() << endl;
    cout << "pass=" << conn_string.getPassword() << endl;
    cout << "db=  " << conn_string.getDatabase() << endl;
    const auto servers = conn_string.getServers();
    for (const auto& server : servers) {
    cout << "serv=" << server << endl;
    }
    cout << "type=" << conn_string.type() << endl;
    // End reality check.
    connection = conn_string.connect(error);
        cout << "error says: " << error << endl;       // Is empty.
        cout << "conn=" << connection << endl;    // Not zero.
    std::cout << "connected ok" << std::endl;
    cout << connection->getConnectionId() << endl;  // Prints "1".

    // This returns an error 13, not authorized, if I included it.
    //cout << "count: " << connection->count("focus_groups") << endl;
} catch( const mongo::DBException &e ) {
    std::cout << "caught " << e.what() << std::endl;
}
cout << "----------------------------------------------------------------------" << endl;
return 0;
}

/*
  Note that I can do this in the mongo shell with no problem:

  jeff@siegfried:~ $ mongo my_host:27017/my_db --ssl -u my_user -p
  MongoDB shell version: 2.6.3
  Enter password:
  connecting to: my_host:27017/my_db
  > db.focus_groups.count()
  26
  >
*/

我在64位ubuntu 15.04上运行,并使用clang 3.6.0进行编译。 Boost是通过apt-get安装的1.55。 我使用ssl支持从HEAD(861699d116627d63e1c914384a66e4e3ea7c23bc)上的git编译并安装了旧版mongo C ++驱动程序。

事实证明这是几件事的融合,但至少是这两件事:

  • 当我编译旧版驱动程序时,默认模式为C ++ 03,它与C ++ 11或C ++ 14不二进制兼容。
  • 驱动程序对boost版本的差异以及使用该版本的客户端的差异很敏感。

一个广泛的话题出现在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM