c++ - 如何通过mongocxx C++驱动上传MongoDB中的文件?

标签 c++ mongodb mongo-cxx-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 .

关于c++ - 如何通过mongocxx C++驱动上传MongoDB中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41504584/

相关文章:

c++ - 如何在不提供有效生成器的情况下告诉 boost::karma::rule 不消耗其属性?

mongodb - 在不同的字段上使用 sort() 索引 MongoDB 以更快地找到 ()

通过类似sql的语法访问mongodb

从 R 调用时 C++ 程序无法运行(符号查找错误)

mongodb - 蒙戈克司机 : how to query based on ISOdate?

c++ - bsoncxx:文档:: View 与文档::值

c++ - 尝试在 MFC 应用程序中使用 QSettings 时出错

c++ - 在 Qt widget/QWindow 上显示过剩窗口

c++ - 错误 "Call to constructor of ' ' is ambiguous",尽管类的构造函数参数看起来不一样?

java - MongoDB 是否提供了生成顺序值的方法?