Insert JSON into Mongocxx Insert JSON into Mongocxx json json

Insert JSON into Mongocxx


A bsoncxx::stdx::string_view can be constructed from a std::string. Simply load your file contents (assuming it contains a single JSON object) into a std::string (perhaps via std::ifstream), and pass that std::string to bsoncxx::from_json. The object returned from bsoncxx::from_json is a bsoncxx::document::value, which is a resource-owning type that contains a BSON document.