File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -58,4 +58,33 @@ int main(int, char**) {
5858 using builder::stream::finalize;
5959 auto myQuery = document{} << " foo"
6060 << " bar" << finalize;
61+
62+ // There is a special concatenate helper to add all keys and corresponding values from one
63+ // document into another.
64+ using bsoncxx::builder::concatenate;
65+ doc << concatenate (myQuery.view ());
66+ // `doc` now looks like:
67+ // {
68+ // "myKey": "myValue",
69+ // ...
70+ // "mySubArr": [...],
71+ // "foo": "bar"
72+ // }
73+
74+ // To nest an existing bsoncxx::document::value into a builder stream, you can create a
75+ // types::b_document and append it. Alternatively you can open a new document and concatenate
76+ // the value in.
77+ bsoncxx::document::value nestedValue = document{} << " nested" << true << finalize;
78+ document topLevelDoc{};
79+ topLevelDoc << " subDoc1" << types::b_document{nestedValue.view ()} << " subDoc2" << open_document
80+ << concatenate (nestedValue.view ()) << close_document;
81+ // `topLevelDoc` now looks like:
82+ // {
83+ // "subDoc1": {
84+ // "nested": true
85+ // },
86+ // "subDoc2": {
87+ // "nested": true
88+ // }
89+ // }
6190}
You can’t perform that action at this time.
0 commit comments