小编zer*_*ool的帖子

将JSON插入Mongocxx

我目前正在尝试将JSON文件插入到我的mongoDB中。我已经看到过去已经通过使用mongo :: BSONObj解决了这个问题……但这似乎不是一个选择,因为他们发布了适用于c ++ 11的新mongocxx驱动程序。这是我在bsoncxx src文件中找到的:

BSONCXX_API document::value BSONCXX_CALL from_json(stdx::string_view json);
/// Constructs a new document::value from the provided JSON text
///
/// @param 'json'
///  A string_view into a JSON document
///
/// @returns A document::value if conversion worked.
///
/// @throws bsoncxx::exception with error details if the conversion failed.
///
Run Code Online (Sandbox Code Playgroud)

如何将JSON文件放入stdx::string_view

谢谢!

c++ json mongodb bson mongo-cxx-driver

2
推荐指数
1
解决办法
1815
查看次数

Mongocxx:如何反向显示文档

我试图相反地显示集合的文档。在 shell 中,这可以通过使用以下命令来完成:

db.testcollection.find().sort({$natural:-1})

在文档中我找到了这个函数:

void sort(bsoncxx::document::view_or_value ordering);

/// The order in which to return matching documents. If $orderby also exists in the modifiers
/// document, the sort field takes precedence over $orderby.
///
/// @param ordering
///   Document describing the order of the documents to be returned.
///
/// @see http://docs.mongodb.org/manual/reference/method/cursor.sort/
Run Code Online (Sandbox Code Playgroud)

如何在 shell 示例中将自然设置为 -1?谢谢!

c++ database mongodb mongo-cxx-driver

1
推荐指数
1
解决办法
1501
查看次数

标签 统计

c++ ×2

mongo-cxx-driver ×2

mongodb ×2

bson ×1

database ×1

json ×1