我想使用 mongo-cxx-driver 上传文件,但找不到方法。尝试使用 mongodb 的 gridfs 功能,但无法集成。使用当前稳定版本 mongodb-cxx-driver (3.1.1)。
gridFs 在尝试像这样存储文件时抛出错误:
gfs.storeFile("filepath", "filename");
错误: store_file:/usr/include/boost/smart_ptr/scoped_ptr.hpp:99: T* boost::scoped_ptr::operator->() const [with T = mongo::AtomicWord]:断言“px != 0”失败。 中止(核心转储)
此外,如果初始化 mongo 客户端,它会提供段错误错误。
#include "mongo/client/dbclient.h"
#include <iostream>
#include <cstdlib>
using namespace std;
using namespace mongo;
int main(int argc, const char** argv) {
cout<<"good so far"<<endl;
client::GlobalInstance instance; //everytime producing segmentation fault
if (!instance.initialized()) {
std::cout << "failed to initialize the client driver: " << instance.status() << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "Successfully initialized the client driver: " << instance.status() << std::endl;
}
return EXIT_SUCCESS;
}
最佳答案
这看起来像旧客户端,而不是稳定的 3.1.1 版本。
GridFS 尚未可用于稳定客户端(最初优先考虑基本的 CRUD 功能),但 GridFS 正在积极开发中,预计将在未来几个月的 3.2.0 版本中可用。如果你想关注进度,相关的 JIRA 票是 CXX-1130 .
关于c++ - 如何通过mongocxx C++驱动上传MongoDB中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41504584/