1
我想使用mongo-cxx-driver來上傳文件,但是找不到方法。試圖使用mongodb的gridfs功能,但無法集成。使用當前穩定版本的mongodb-cxx-driver(3.1.1)。如何通過mongocxx C++驅動程序上傳MongoDB中的文件?
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'失敗。 Aborted(核心轉儲)
此外,如果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;
}
非常感謝。有一件事我不明白,爲什麼客戶端驅動程序在**「mongo-cxx-driver/src/mongo/client/examples」**文件夾中被初始化爲舊式客戶端。 另外一個問題,請你給我一個關於爲什麼分段錯誤發生,如果我使用舊客戶端? –
你可以給一個顯示段錯誤的[SSCCE](http://sscce.org)嗎? – xdg
我編輯了這個問題並提供了一個示例代碼。 謝謝。 –