将BSON数组添加到MongoDB 3.2文档并提取返回的值(MongoCXX 3.2)(C+;+;11) //文档我想添加数据并从C++中提取它 bsoncxx::builder::stream::文档数据\u生成器, //我想尝试在我的文档中保存这个数组,因为我想稍后填充它 bsoncxx::builder::stream::array mybsonarr; 对于(浮动i=0;i
用于将数组添加到流文档中,请使用将BSON数组添加到MongoDB 3.2文档并提取返回的值(MongoCXX 3.2)(C+;+;11) //文档我想添加数据并从C++中提取它 bsoncxx::builder::stream::文档数据\u生成器, //我想尝试在我的文档中保存这个数组,因为我想稍后填充它 bsoncxx::builder::stream::array mybsonarr; 对于(浮动i=0;i,c++,arrays,mongodb,c++11,mongo-cxx-driver,C++,Arrays,Mongodb,C++11,Mongo Cxx Driver,用于将数组添加到流文档中,请使用打开数组: // The document I want to add data to and extract it back from c++ bsoncxx::builder::stream::document data_builder, // I want to try and save this array in my document , as I want to populate it later
打开数组
:
// The document I want to add data to and extract it back from c++
bsoncxx::builder::stream::document data_builder,
// I want to try and save this array in my document , as I want to populate it later
bsoncxx::builder::stream::array mybsonarr;
for(float i = 0 ; i < 5 ; i = i + 0.1f){
mybsonarr << i;
}
// Now this line Throws an error
data_builder << "_id" << 5 << "my_array" << &mybsonarr;
使用bsoncxx::builder::stream::document;
使用bsoncxx::builder::stream::open_数组;
使用bsoncxx::builder::stream::close_数组;
使用bsoncxx::builder::stream::finalize;
文件数据{};
data_builder如何使用最新的mongocxx执行此操作?不再有stream::open_数组。。。
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;