gpt4 book ai didi

c++ - [bsoncxx ]如何将 bsoncxx::document::element 附加到 bsoncxx::builder::basic::document?

转载 作者:行者123 更新时间:2023-11-30 01:06:54 31 4
gpt4 key购买 nike

尝试将元素附加到文档时出现错误。

bsoncxx::document::value _obj;  //This is Declaration of _obj in diffrent file

bsoncxx::document::element element = _obj.view()[sFieldName];
if (element.length() && element.type() == bsoncxx::type::k_document)
{
bsoncxx::builder::basic::document bsonBuilder;
bsonBuilder.append(element); //Getting Error
}

Error: Error C2664 'void bsoncxx::v_noabi::builder::basic::sub_document::append_(bsoncxx::v_noabi::builder::concatenate_doc)': cannot convert argument 1 from 'bsoncxx::v_noabi::document::element' to 'bsoncxx::v_noabi::builder::concatenate_doc'

请帮我解决这个问题,如何将元素转换为文档或将元素附加到文档。

谢谢

最佳答案

要将元素附加到构建器,您需要使用 bsoncxx::builder::basic::kvp 并分别传入元素的键和值:

using bsoncxx::builder::basic::kvp;

bsoncxx::document::element elem = ...;
bsoncxx::builder::basic::document builder;
builder.append(kvp(elem.key(), elem.get_value()));

关于c++ - [bsoncxx ]如何将 bsoncxx::document::element 附加到 bsoncxx::builder::basic::document?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45413180/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com