2017-06-14 71 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:是的你是对的,他们不在发布分支。他们应该在例子中提到,奇怪的事情...... –