我目前正在尝试将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?
谢谢!
我试图相反地显示集合的文档。在 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?谢谢!