2

我想使用 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;
}
4

1 回答 1

0

这看起来像是旧版客户端,而不是稳定的 3.1.1 版本。

GridFS 还不能用于稳定的客户端(最初的优先级是基本的 CRUD 功能),但 GridFS 正在积极开发中,预计在未来几个月内将在 3.2.0 版本中可用。如果您想关注进度,相关的 JIRA 票证是CXX-1130

于 2017-01-09T14:38:57.810 回答