[SERVER-1198] BSONObjBuilder.merge( BSONObj o ) - add fields not already there Created: 07/Jun/10  Updated: 24/Feb/17  Resolved: 24/Feb/17

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 1.5.2
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Andrea Fontana Assignee: Unassigned
Resolution: Incomplete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

If we have some BSONObj with similar structure and we append them using the same BSONObjBuilder, the resulting BSONObjectBuilder.obj() is malformed...

For example:

BSONObj o[5] =

{ BSON("subobj" << BSON("text" << "old-text-val")), BSON("subobj" << BSON("field" << "other-field-val")), BSON("subobj" << BSON("text" << "new-text-val")), BSON("simple" << 3), BSON("other" << 4) }

;

BSONObjBuilder b;
for (unsigned int i=0; i<5; ++i) b.appendElements(o[i]);

Resulting object from builder have three different 'subobj' fields. And if you insert this obj in database these three fields become identical (and repeated).

It would be useful if BSONObjBuilder could merge objects overwriting similar fields, so the previous code will gives an object like this:

{
"subobj" :

{"text" : "new-text-val", "field" : "other-field-val"}

,
"simple" : 3,
"other" : 4
}

and not like this one (current behaviour):

{
"subobj" :

{"text" : "old-text-val"}

,
"subobj" :

{"field" : "other-field-val"}

,
"subobj" :

{"text" : "new-text-val"}

,
"simple" : 3,
"other" : 4
}

if you insert this object in db, and then you retrieve it, you'll read:

{
"subobj" :

{"text" : "old-text-val"}

,
"subobj" :

{"text" : "old-text-val"}

,
"subobj" :

{"text" : "old-text-val"}

,
"simple" : 3,
"other" : 4
}



 Comments   
Comment by Eric Milkie [ 24/Feb/17 ]

The legacy C++ driver is no longer in active development.

Generated at Thu Feb 08 02:56:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.