0
將數組添加到文檔時,open_array和close_array在投入文檔流時必須同時發生。在添加'close_array'時,後面的代碼在最後一行失敗(編譯時間)。MongoDB C++,未能將數組添加到文檔中
vector<string> List;
...
document Doc;
Doc <<"List" <<open_array;
for (string Str: List) {
Doc <<Str;
}
Doc <<close_array;
但我不知道「列表」中要添加到文檔的元素數量。 MongoDB仍然缺少C++驅動程序的示例。
此代碼有效,但「列表」中的項目數量未知。
Doc
<<open_array
<<List[0] <<List[1] <<List[2] <<...
<<close_array;
G ++錯誤:
content.cpp:65:7: error: no match for ‘operator<<’ (operand types are ‘bsoncxx::v_noabi::builder::stream::document’ and ‘const bsoncxx::v_noabi::builder::stream::close_array_type’)
Doc <<close_array;
~~~~^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
你知道,如果在3.0工作嗎?我認爲它不... –
我建立從https://github.com/mongodb/mongo-cxx-driver/archive/r3.1.0.tar.gz的mongodb C++驅動程序3.1.0 – johnlowvale
像在代碼在我的答案工作正常 – johnlowvale