2017-06-14 83 views
1

我使用基於mongo-c-driver-1.6.2的mongo-cxx-driver-r3.1.1。 使用latest examples provided on github,我設法找到了如何連接數據庫以及如何保存文檔。在mongodb C++驅動程序中使用聲明「未找到」

我很努力地按照mongocxx/query.cpp example中提供的信息使用過濾器獲取結果。

對make_document方法有很多調用,但是我沒有使用該名稱的bsoncxx命名空間中的類/方法/模板(與make_array的問題相同)。

繼承人是在包括using指令和using聲明:

#include <bsoncxx/builder/basic/document.hpp> 
#include <bsoncxx/builder/basic/array.hpp> 
#include <bsoncxx/builder/basic/kvp.hpp> 
#include <bsoncxx/types.hpp> 
#include <bsoncxx/json.hpp> 
#include <bsoncxx/stdx/make_unique.hpp> 
#include <bsoncxx/stdx/optional.hpp> 
#include <bsoncxx/stdx/string_view.hpp> 

#include <mongocxx/instance.hpp> 
#include <mongocxx/pool.hpp> 
#include <mongocxx/stdx.hpp> 
#include <mongocxx/client.hpp> 
#include <mongocxx/logger.hpp> 
#include <mongocxx/uri.hpp> 
#include <mongocxx/exception/exception.hpp> 
#include <mongocxx/options/find.hpp> 

using namespace mongocxx; 
using namespace bsoncxx; 

using bsoncxx::builder::basic::document; 
using bsoncxx::builder::basic::kvp; 
using bsoncxx::builder::basic::sub_document; 
using bsoncxx::builder::basic::sub_array; 
using bsoncxx::builder::basic::array; 
using bsoncxx::types::value; 
using mongocxx::result::insert_one; 

的使用聲明 「未找到」:

using bsoncxx::builder::basic::make_array; 
using bsoncxx::builder::basic::make_document; 

我失去了一些東西明顯? 有更近的例子嗎?

+0

奇怪的是,'make_document'在[document.hpp]中(https://github.com/mongodb/mongo-cxx-driver/blob/master/src/bsoncxx/builder/basic/document.hpp)和'make_array'在[array.hpp]中(https://github.com/mongodb/mongo-cxx-driver/blob/master/src/bsoncxx/builder/basic/array.hpp),你都包括在內。你能否提供你的編譯器的實際錯誤信息? –

+0

謝謝!你幫我注意到我的document.hpp沒有包含make_document模板(和array.hpp的make_array模板)。 我打算在今天下午添加它們並進行測試。有消息通知你。 – Francois

回答

0

您的代碼看起來不錯,因爲您包含了所有必需的頭文件make_documentmake_array。 您在評論中提到,document.hpp不包含make_document,並且array.hpp不包含make_array模板。 這是正確的版本mongo-cxx-driver-r3.1.1

在當前主分支中,您可以看到頭文件,如果您按照它們的源鏈接:document.hpparray.hpp。你使用的例子可能是新的主分支,因爲它們也來自git的當前分支。

+0

源代碼來自[mongocxx github發佈頁面] [1]的最新版本(r3.1.1)。 [1]:https://github.com/mongodb/mongo-cxx-driver/releases – Francois

+0

我注意到你提供的hpp文件的鏈接導向master分支。 事情是我使用的穩定版本是穩定版本/發行版本。 我無法找到添加模板的提交,但它解釋了爲什麼我找不到它們。 非常感謝您的幫助。 – Francois

+0

@Francois:是的你是對的,他們不在發佈分支。他們應該在例子中提到,奇怪的事情...... –

相關問題