2017-01-06 37 views
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; 
} 

回答

0

這看起來像舊式客戶端,而不是穩定的3.1.1版本。 GridFS目前尚未提供給穩定客戶端(最初的優先級是基本的CRUD功能),但GridFS正在積極開發之中,並將在未來幾個月的3.2.0版本中提供。如果您想關注進度,相關的JIRA票證是CXX-1130

+0

非常感謝。有一件事我不明白,爲什麼客戶端驅動程序在**「mongo-cxx-driver/src/mongo/client/examples」**文件夾中被初始化爲舊式客戶端。 另外一個問題,請你給我一個關於爲什麼分段錯誤發生,如果我使用舊客戶端? –

+0

你可以給一個顯示段錯誤的[SSCCE](http://sscce.org)嗎? – xdg

+0

我編輯了這個問題並提供了一個示例代碼。 謝謝。 –

相關問題