[英]How to upload files in MongoDB through mongocxx C++ driver?
我想使用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 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.