【问题标题】:Using declaration "not found" in mongodb c++ driver在 mongodb c++ 驱动程序中使用声明“未找到”
【发布时间】:2017-06-14 09:34:23
【问题描述】:

我正在使用基于 mongo-c-driver-1.6.2 的 mongo-cxx-driver-r3.1.1。 使用latest examples provided on github,我设法找到了如何连接数据库以及如何保存文档。

我正在努力按照mongocxx/query.cpp example 中提供的信息使用过滤器获取结果。

对 make_document 方法有很多调用,但我在 bsoncxx 命名空间中没有具有该名称的类/方法/模板(与 make_array 相同的问题)。

这是包含、使用指令和使用声明:

#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_documentdocument.hpp 中,make_arrayarray.hpp 中,你们都包括在内。您能否提供您的编译器的实际错误消息?
  • 谢谢!您帮助我注意到我的 document.hpp 不包含 make_document 模板(和 array.hpp make_array 模板)。我将添加它们并在今天下午进行测试。我会及时通知你的。

标签: c++ mongodb


【解决方案1】:

您的代码看起来正确,因为您包含了make_documentmake_array 所需的所有必要头文件。 您在评论中说,document.hpp 不包含make_documentarray.hpp 不包含make_array 模板。 这适用于发布mongo-cxx-driver-r3.1.1

在当前的主分支中,头文件存在,您可以查看它们的源链接:document.hpparray.hpp。您使用的示例可能用于新的 master 分支,因为它们也来自 git 的当前分支。

【讨论】:

  • 源代码来自[mongocxx github发布页面][1]的最新版本(r3.1.1)。 [1]:github.com/mongodb/mongo-cxx-driver/releases
  • 我注意到您提供的 hpp 文件的链接指向主分支。问题是我正在使用的稳定版本位于 stable/release 分支上。我找不到添加模板的提交,但它解释了为什么我找不到它们。非常感谢您的帮助。
  • @Francois:是的,你是对的,它们不在发布分支中。他们应该在例子中提到,奇怪的事情......
猜你喜欢
  • 1970-01-01
  • 2023-03-20
  • 2017-04-10
  • 2020-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-23
  • 2023-03-02
相关资源
最近更新 更多