如何通过mongocxx C++驱动程序在MongoDB中上传文件



我想使用 mongo-cxx 驱动程序上传文件,但找不到方法。尝试使用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 [使用 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。

最新更新