Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-1198

BSONObjBuilder.merge( BSONObj o ) - add fields not already there

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Incomplete
    • Icon: Major - P3 Major - P3
    • None
    • 1.5.2
    • Internal Client
    • None

    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
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            trikko Andrea Fontana
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: