如何使用C 将Boost Ptree插入MongoDB

How to insert a Boost ptree into MongoDB using C++

本文关键字:Ptree 插入 MongoDB Boost 何使用      更新时间:2023-10-16

我在https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/tutororial/complocile/上汇总并准备好了,用文字数据进行了测试。<<<<<<<<<<<<<<<<<<<,/p>

但挑战是如何将Boost Ptree存储到MongoDB中。我有一个Boost Ptree,因为我正在使用Boost来解析JSON字符串。

该过程如下:

输入 -> JSON String(OK) -> Boost Ptree(OK) -> MongoDB插入(Stuck!)

最终得到了解决方案!

这些是:

  • 可以从解析JSON String(Boost Read_json)
  • 获得Ptree
  • 检查或修改PTREE对象中的值
  • 使用boost write_json
  • 将ptree转换回JSON字符串
  • 转换为mongodb bson值: bsoncxx :: document :: value doc = bsoncxx :: from_json(str)
  • 插入到db: cxxclient [" dbName"] [" collection"]。