[CXX-789] Modify BSONObj Created: 28/Dec/15  Updated: 11/Sep/19  Resolved: 30/Dec/15

Status: Closed
Project: C++ Driver
Component/s: API, BSON
Affects Version/s: legacy-1.1.0
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: xie yang yang Assignee: Unassigned
Resolution: Done Votes: 0
Labels: legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

windows



 Description   

I want to save records as BSONObj in memory, then we can access them easier, when out logic modify records we can modify the data in memory and update them in database, but now we can not modify BSONObj,how can we do this now



 Comments   
Comment by Andrew Morrow (Inactive) [ 30/Dec/15 ]

xyysnybzi - I'm glad you found a solution that works for you. I'm closing this ticket but feel free to ping back on the ticket if you need further clarification.

Comment by xie yang yang [ 30/Dec/15 ]

Thank you! I have try to save them with boost::any and it seem work well, for the example i have find the APIs from source: BSONObjBuilder::appendElements(BSONObj x) and BSONObjBuilder::appendElementsUnique(BSONObj x) and i will try them when i need.
Thank you again!

Comment by Andrew Morrow (Inactive) [ 28/Dec/15 ]

I don't fully understand your question. Are you asking for a client side API that will allow you to locally modify in-memory BSON objects once you have retrieved them from the database? If so, we don't currently offer such an API in the C++ driver. You can, however, use the BSONObjBuilder and BSONArrayBuilder classes to start constructing a new object, and then write the changed and unchanged portions based on the BSONElement values extracted from the source object. Please let me know if you would like an example of how to do so.

Generated at Wed Feb 07 22:00:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.