将 MongoDB C++ 驱动程序升级到 mongocxx-3.1.2

Upgrading MongoDB C++ Driver to mongocxx-3.1.2

如何从 mongoDB C++ 驱动程序从 Legacy 轻松升级到 mongocxx-3.1.2? mongocxx-3.1.2 中的 类 有哪些后续内容?

mongo::BSONElement;
mongo::BSONObj;
mongo::BSONObjBuilder;

提前致谢..

没有 "upgrade" - 这些库提供完全不同的 API。您将需要重新编写与 BSON 或 MongoDB 交互的应用程序部分才能使用它(您还需要现代 C++ 工具链)。

要了解您所问类型的类似物,我建议阅读 https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/working-with-bson/

当前稳定版本库 (3.1.2) 的完整文档可在此处获得:https://mongodb.github.io/mongo-cxx-driver/api/current/

详细说明您请求的类型的映射:

  • 最接近mongo::BSONElement的是bsoncxx::document::element
  • 最接近 mongo::BSONObj 的类似物是 bsoncxx::document::value 及其关联的视图类型 bsoncxx::document::view
  • 最接近mongo::BSONObjBuilder的是bsoncxx::builder::basic::document