我想使用 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]: Assertion `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;
}