Adding a BSON Array to a MongoDB 3.2 document and extracting the values back ( MongoCXX 3.2 ) ( C++ 11)
For adding array to stream document use open_array
:
using bsoncxx::builder::stream::document; using bsoncxx::builder::stream::open_array; using bsoncxx::builder::stream::close_array; using bsoncxx::builder::stream::finalize; document data_builder{}; data_builder << "_id" << 5; auto array_builder = data_builder << "my_array" << open_array; for (float i = 0 ; i < 5 ; i = i + 0.1f) { array_builder << i; } array_builder << close_array; bsoncxx::document::value doc = data_builder << finalize; std::cout << bsoncxx::to_json(doc) << std::endl;