我尝试基于official documentation来做。下面是代码,我尝试向数组中添加一些项:
auto in_array = bsoncxx::builder::stream::document{}
<< "$set" << open_document << call_id_key << call_id << close_document << "$push"
<< open_document << transcription_key
<< open_array << open_document << direction_key << "INBOUND" << text_key
<< transcript << confidence_key << confidence
<< start_time_key << start_time << end_time_key << end_time
<< "words" << open_array;
for (const auto& word_info : words) {
in_array = in_array << open_document << "word" << word_info.first <<
"confidence" << word_info.second << close_document; // Assertion happens here
}
bsoncxx::document::value doc = in_array << close_array << close_document << close_array << close_document << finalize;
std::cout << bsoncxx::to_json(doc.view()) << std::endl;
1条答案
按热度按时间eulz3vhy1#
我刚刚碰到了同样的问题,正如SPM所指出的,必须将文档创建与数组创建分开: