auto cursor = db["friend"].find({});
for (auto &&docView : cursor) {
bsoncxx::builder::basic::document document1;
document1.append(docView); // This line will be an error
document1.append(kvp("surl", "http://xxx"));
document1.append(kvp("burl", "http://xxx"));
arr.append(document1);
}
I want to create a new document, contains the query result, and add some new field into the document.But the above code can't run. Who can tell me what to do, thank you!
query result docView like this:
{
"name": "BeJson",
"headUrl": "http://www.bejson.com"
}
I want build document1 like this:
{
"name": "BeJson",
"headUrl": "http://www.bejson.com",
"surl": "http://xxx",
"burl": "http://xxx"
}
I think, if I understand your question, that you should use builder::concatenate
:
auto cursor = db["friend"].find({});
for (auto &&docView : cursor) {
bsoncxx::builder::basic::document document1;
document1.append(bsoncxx::builder::concatenate(docView));
document1.append(kvp("surl", "http://xxx"));
document1.append(kvp("burl", "http://xxx"));
}