我使用基于 mongo-c-driver-1.6.2 的 mongo-cxx-driver-r3.1.1。
使用github 上提供的最新示例,我设法找到了如何连接数据库以及如何保存文档。
我正在努力使用过滤器按照中提供的信息获取结果mongocxx/query.cpp 示例.
有很多对 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;
我错过了一些明显的东西吗?
还有最近的例子吗?
您的代码看起来是正确的,因为您包含了所需的所有必需的头文件make_document
and make_array
。
你在评论中说,文档.hpp不包含make_document
和数组.hpp不包含make_array
模板。
这正适合发布mongo-cxx-driver-r3.1.1
.
在当前的 master 分支中,如果您点击它们的源链接,就可以看到头文件的存在:文档.hpp and 数组.hpp。您使用的示例可能适用于新的 master 分支,因为它们也来自 git 的当前分支。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)