gpt4 book ai didi

c++ - MongoDB C++ 驱动断言失败

转载 作者:太空宇宙 更新时间:2023-11-04 11:58:32 25 4
gpt4 key购买 nike

问题

当我尝试使用 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...

插入文档(different_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();

}

最佳答案

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

mongo::DBClientConnection DBConn( "localhost" );

为此:

mongo::DBClientConnection DBConn;

DBConn.connect( "localhost" );

关于c++ - MongoDB C++ 驱动断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15122595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com