1

问题

当我尝试使用 C++ 驱动程序将文档插入 MongoDB 时,我收到以下异常消息:

Wed Feb 27 15:21:38   Assertion failure p src/mongo/client/dbclientinterface.h 1096
0 assertion src/mongo/client/dbclientinterface.h:1096

据我所知,它似乎与端口号有关?dbclientinterface.h:1096 包含以下行:

MessagingPort& port() { verify(p); return *p; } 

设置连接 (main.cpp)

mongo::DBClientConnection DBConn( "localhost" );
mongo::DBClientConnection DBConn( "localhost:27017" ); // I've also tried this...

插入一个文档 (differ_file.h)

while( m_Entries.size() ){
    JsonBox::Value Data( m_Entries.front() );

    try {
        std::stringstream   JSONDoc;
        mongo::BSONObj      BSONDoc;

        Data["doc"].writeToStream( JSONDoc, false );
        BSONDoc = mongo::fromjson( JSONDoc.str() );

        // std::cout << Data["ns"].getString() << std::endl;
        // std::cout << BSONDoc.toString() << std::endl;

        // This is where the exception is thrown...
        m_DBConn.insert( Data["ns"].getString(), BSONDoc );

    } catch( const mongo::DBException& e ){
        std::cout << e.toString() << std::endl;

    }

    m_EntriesMutex.lock();
    m_Entries.pop();
    m_EntriesMutex.unlock();

}
4

1 回答 1

1

我在文档中简单地翻了一下,偶然发现了一个令人吃惊的事实,即您无法从构造函数连接到 mongodb 数据库。我不得不改变这个:

mongo::DBClientConnection DBConn( "localhost" );

对此:

mongo::DBClientConnection DBConn;

DBConn.connect( "localhost" ); 
于 2013-02-28T18:37:02.877 回答