文档的 mongdb c++ 驱动程序编译错误{}

莫帕西·拉文德拉纳特

我正在尝试将 mongodb 与最新的 c++ 驱动程序一起使用,以参考示例

我的代码如下:

#include <mongocxx/client.hpp>
#include <mongocxx/options/find.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>

using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::open_document;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::finalize;

class MongoDBApiUtils {

  public :
    MongoDBApiUtils(){}
    static json validateDoc(const std::string& key ,const json& regInfo);
    static json validatePreRegistration(const json& regInfo);
    static bool checkUserExist(const json& regInfo);
    static bool checkUserBlackList(const json& regInfo);


    /* 
     * Retrieves a latest block from blockchain, based on the 
     * given query field.  It is assumed that the database is
     * indexed on the queryField, to avoid O(n) problem.
     **/
    static json getLatestBlock(
          const mongocxx::database& db, const std::string& filter) {
      auto cursor = db["ctlblocks"].find_one(document{} << filter << finalize);
    }

    /** Creates and adds a new block into the blockchain **/
    static json addBlock(json& current, const json& prev) {

    }

  private :

};

#endif

但是我收到编译错误,我无法破译。它通过调用该find_one方法在我尝试创建游标的行上给出错误

In file included from /Volumes/second/nvi/github/blockchain_db/src/Impl/mongo/src/mongo_db_api.cpp:3:
/Volumes/second/nvi/github/blockchain_db/src/Impl/mongo/src/mongo_db_api_utils.hpp:47:46: error: no viable conversion from 'typename std::enable_if<!util::is_functor<const finalize_type &, void (single_context)>::value, key_context<closed_context> >::type' (aka 'bsoncxx::v_noabi::builder::stream::key_context<bsoncxx::v_noabi::builder::stream::closed_context>') to 'bsoncxx::document::view_or_value' (aka 'view_or_value<document::view, document::value>')
      auto cursor = db["ctlblocks"].find_one(document{} << filter << finalize);
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/bsoncxx/v_noabi/bsoncxx/view_or_value.hpp:60:20: note: candidate constructor not viable: no known conversion from 'typename std::enable_if<!util::is_functor<const finalize_type &, void (single_context)>::value, key_context<closed_context> >::type' (aka 'bsoncxx::v_noabi::builder::stream::key_context<bsoncxx::v_noabi::builder::stream::closed_context>') to 'bsoncxx::v_noabi::document::view' for 1st argument
    BSONCXX_INLINE view_or_value(View view) : _view{view} {
                   ^   
/usr/local/include/bsoncxx/v_noabi/bsoncxx/view_or_value.hpp:69:20: note: candidate constructor not viable: no known conversion from 'typename std::enable_if<!util::is_functor<const finalize_type &, void (single_context)>::value, key_context<closed_context> >::type' (aka 'bsoncxx::v_noabi::builder::stream::key_context<bsoncxx::v_noabi::builder::stream::closed_context>') to 'bsoncxx::v_noabi::document::value &&' for 1st argument
    BSONCXX_INLINE view_or_value(Value&& value) : _value(std::move(value)), _view(*_value) {
                   ^   
/usr/local/include/bsoncxx/v_noabi/bsoncxx/view_or_value.hpp:75:20: note: candidate constructor not viable: no known conversion from 'typename std::enable_if<!util::is_functor<const finalize_type &, void (single_context)>::value, key_context<closed_context> >::type' (aka 'bsoncxx::v_noabi::builder::stream::key_context<bsoncxx::v_noabi::builder::stream::closed_context>') to 'const bsoncxx::v_noabi::view_or_value<bsoncxx::v_noabi::document::view, bsoncxx::v_noabi::document::value> &' for 1st argument
    BSONCXX_INLINE view_or_value(const view_or_value& other)
                   ^   
/usr/local/include/bsoncxx/v_noabi/bsoncxx/view_or_value.hpp:93:20: note: candidate constructor not viable: no known conversion from 'typename std::enable_if<!util::is_functor<const finalize_type &, void (single_context)>::value, key_context<closed_context> >::type' (aka 'bsoncxx::v_noabi::builder::stream::key_context<bsoncxx::v_noabi::builder::stream::closed_context>') to 'bsoncxx::v_noabi::view_or_value<bsoncxx::v_noabi::document::view, bsoncxx::v_noabi::document::value> &&' for 1st argument
    BSONCXX_INLINE view_or_value(view_or_value&& other) noexcept

任何想法如何解决这个问题?

生活用水

您不在正确的流上下文中传递finalize,因为您只向流提供了一个值。要使用流构建器,您需要传递一个键,然后传递它的值:

auto result = document{} << k1 << v1 << k2 << v2 << ... kn << vn << finalize

为您提供一个包含表示 JSON 的 BSON 对象的结果对象

{ 'k1' : v1, 'k2' : v2, ... 'kn' : vn }

您的代码只提供了类似的东西,所以文档流不处于接受状态finalize.

如果您的整个过滤器是一个 JSON 字符串,那么只需将其转换为 BSON 并带有bsoncxx::from_json. 另请注意,由于这种混淆和误用的机会,基于流的文档构建器或多或少地被淡化了。

您可能会从basic建筑商那里获得更好的里程

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用 MongDB C# 驱动程序连接两个集合的查询中的 NOT IN 过滤器

来自分类Dev

mongoDB c ++ 11驱动程序获取插入文档的ID

来自分类Dev

从C ++程序编译LaTeX文档

来自分类Dev

从驱动程序v1迁移C#驱动程序v2中的更新文档

来自分类Dev

从驱动程序v1迁移C#驱动程序v2中的更新文档

来自分类Dev

如何使用C#驱动程序更新MongoDB中数组子文档中包含的数组子文档中的字段?

来自分类Dev

如何使用C#驱动程序更新MongoDB中数组子文档中包含的数组子文档中的字段?

来自分类Dev

MongoDb C#驱动程序是否可以使用LINQ和动态文档?

来自分类Dev

MongoDB C#驱动程序-更新许多文档时的性能问题

来自分类Dev

如何使用C#驱动程序删除mongodb文档中的嵌套数组元素

来自分类Dev

是否使用C#驱动程序可用于MongoDB的文档验证器?

来自分类Dev

MongoDB C#驱动程序-如何查询子文档数组上的属性

来自分类Dev

复合查询以在MongoDb C#驱动程序中查找文档

来自分类Dev

使用C#驱动程序上的复杂查询从集合中删除文档

来自分类Dev

使用C#驱动程序在mongodb中查找计算值最高的文档

来自分类Dev

MongoDB C#驱动程序2.0-更新文档

来自分类Dev

使用C#.NET驱动程序2.0投影mongodb子文档

来自分类Dev

MongoDB C ++驱动程序3.0以字符串形式获取文档并避免使用json

来自分类Dev

MongoDB C#驱动程序-更新嵌入式文档数组中的所有字段

来自分类Dev

带有聚合管道的MongoDB C#驱动程序更新文档

来自分类Dev

如何使用mongodb C#驱动程序获取子文档的集合?

来自分类Dev

MongoDb C#驱动程序可以与LINQ和动态文档一起使用吗?

来自分类Dev

使用C#驱动程序上的复杂查询从集合中删除文档

来自分类Dev

复合查询以在MongoDb C#驱动程序中查找文档

来自分类Dev

使用C#驱动程序在mongodb中查找计算值最高的文档

来自分类Dev

如何在MongoDB C#驱动程序中按值的字段范围选择文档?

来自分类Dev

无法使用.Net驱动程序2.0在mongodb c#中保存文档

来自分类Dev

是否使用C#驱动程序可用于MongoDB的文档验证器?

来自分类Dev

Mongo C ++驱动程序能够绕过文档结构规则(关于键不是以$开头的规则)

Related 相关文章

  1. 1

    使用 MongDB C# 驱动程序连接两个集合的查询中的 NOT IN 过滤器

  2. 2

    mongoDB c ++ 11驱动程序获取插入文档的ID

  3. 3

    从C ++程序编译LaTeX文档

  4. 4

    从驱动程序v1迁移C#驱动程序v2中的更新文档

  5. 5

    从驱动程序v1迁移C#驱动程序v2中的更新文档

  6. 6

    如何使用C#驱动程序更新MongoDB中数组子文档中包含的数组子文档中的字段?

  7. 7

    如何使用C#驱动程序更新MongoDB中数组子文档中包含的数组子文档中的字段?

  8. 8

    MongoDb C#驱动程序是否可以使用LINQ和动态文档?

  9. 9

    MongoDB C#驱动程序-更新许多文档时的性能问题

  10. 10

    如何使用C#驱动程序删除mongodb文档中的嵌套数组元素

  11. 11

    是否使用C#驱动程序可用于MongoDB的文档验证器?

  12. 12

    MongoDB C#驱动程序-如何查询子文档数组上的属性

  13. 13

    复合查询以在MongoDb C#驱动程序中查找文档

  14. 14

    使用C#驱动程序上的复杂查询从集合中删除文档

  15. 15

    使用C#驱动程序在mongodb中查找计算值最高的文档

  16. 16

    MongoDB C#驱动程序2.0-更新文档

  17. 17

    使用C#.NET驱动程序2.0投影mongodb子文档

  18. 18

    MongoDB C ++驱动程序3.0以字符串形式获取文档并避免使用json

  19. 19

    MongoDB C#驱动程序-更新嵌入式文档数组中的所有字段

  20. 20

    带有聚合管道的MongoDB C#驱动程序更新文档

  21. 21

    如何使用mongodb C#驱动程序获取子文档的集合?

  22. 22

    MongoDb C#驱动程序可以与LINQ和动态文档一起使用吗?

  23. 23

    使用C#驱动程序上的复杂查询从集合中删除文档

  24. 24

    复合查询以在MongoDb C#驱动程序中查找文档

  25. 25

    使用C#驱动程序在mongodb中查找计算值最高的文档

  26. 26

    如何在MongoDB C#驱动程序中按值的字段范围选择文档?

  27. 27

    无法使用.Net驱动程序2.0在mongodb c#中保存文档

  28. 28

    是否使用C#驱动程序可用于MongoDB的文档验证器?

  29. 29

    Mongo C ++驱动程序能够绕过文档结构规则(关于键不是以$开头的规则)

热门标签

归档