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

$set cannot update an embedded object and create an embedded object at the same time

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.3.1
    • Affects Version/s: 0.9.7
    • Component/s: Write Ops
    • None

      I found this bug (I think):

      // create an object with an embedded set of objects
      db.example.insert({_id:1,set:[

      {key1:'v1'}

      ]});

      // now updated key1 in set and add an embedded object
      // the relevant objects are separate from each other so it should work
      db.example.update({_id:1}, { $set : { 'set.0.key1' : 'v2', 'new.key' : 'bla' }});

      // however it doesn't
      db.getPrevError()
      "

      {"err" : "Modifier spec implies existence of an encapsulating object with a name that already represents a non-object, or is referenced in another $set clause" , "n" : 0 , "nPrev" : 1 , "ok" : 1}

      "

      // doing the updates separate from each other does work:
      > db.example.update({_id:1},{$set: { 'set.0.key1' : 'v3' }});
      > db.example.update({_id:1},{$set: { 'new.key' : 2 }});
      > db.example.find()
      {"_id" : 1 , "set" : [

      {"key1" : "v3"}

      ] , "new" : {"key" : 2}}

      I guess, somehow it is not possible to use $set to create a new embedded object while at the same time updating an existing embedded object.

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            wouter Wouter
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: