In the c# mongodb driver (version 2.3) it is very easy to modify an existing bson document. However, the c++ driver (version v3) seems to provide only a read-only view of a existing document or the builder for new documents. Did I overlook some features of the c++ driver or does the c++ driver really miss the modify functionality or does the c# driver just simulated the modification by internally copying the original document and adding the modification into the new document?
The C++ driver models the BSON document internally as a byte array for efficiency, not as a map or other read/write data structure. The C# RawBsonDocument class is the nearest equivalent.
If you need to inflate, modify and deflate in C++, that has to be done by the users. For example, define a class/struct representing a document, and a constructor that takes a bsoncxx::document::view
and iterates it to populate the struct fields of interest. Then create a method that walks the members of the class/struct, appends them to a new document via one of the builder classes, and returns that.