如何使用 mongocxx c++ 驱动递归生成 Mongodb 文档?1.我使用mongocxx c++驱动v.3和c++11。2. 这是我的 main.cpp 方法,它解析十六进制字符串并生成这样的 mongocxx 代码: console:$ ./main dissect 0x160301012c01000128030340c70e243001b96d8c 和输出:
<< "MainType" << bsoncxx::builder::stream::open_document
<< "TLSRecord" << bsoncxx::builder::stream::open_document
<< "type"<< "16"
<< "version"<< "0301"
<< "length"<< "012C"
<< "hsMsg" << bsoncxx::builder::stream::open_document
<< "type"<< "01"
<< "length"<< "000128"
<< "clientHello" << bsoncxx::builder::stream::open_document
<< "version"<< "0303"
<< "random"<< "40C70E243001B96D8C"
<< "session_id_length"<< ""
<< bsoncxx::builder::stream::close_document
<< bsoncxx::builder::stream::close_document
<< bsoncxx::builder::stream::close_document
在此之后,我需要将它推送到 mongodb 中。
从 dissect 方法调用连接方法 form main.cpp 十六进制字符串解析后调用 mongodb 连接
创建 mongodbConnection:
调用 MongodbMapper 将生成的代码映射到 db
调用 GenerateDocument 自动生成 Connect -> Mapp -> Generate -> Insert
在这里我被堆叠了,尝试编译它时出错。
src/MongodbMapper.cpp:76:6: note: candidate function not viable: no known conversion from
'bsoncxx::v_noabi::builder::stream::key_context<bsoncxx::v_noabi::builder::stream::key_context<bsoncxx::v_noabi::builder::stream::closed_context> >' to
'bsoncxx::builder::stream::document &' for 3rd argument void generateDocument(DataUnit& node, int level, bsoncxx::builder::stream::document& doc) {