将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.
///

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

谢谢!

DHW

bsoncxx::stdx::string_view可以从构成std::string只需将文件内容(假设它包含一个JSON对象)加载到中std::string(可能通过std::ifstream),然后将其传递std::string给即可bsoncxx::from_json从返回的对象bsoncxx::from_jsonbsoncxx::document::value,这是包含BSON文档的资源拥有类型。

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

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

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章