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

Setting _id in upsert() operation that uses $set

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.2.1
    • Component/s: None
    • Labels:
      None
    • Environment:
      no matter

      I want to add object with CERTAIN _id if object doesn't exist. Else, I want to use $set on it's properties.
      What should I do?

      > db.chatsessions.update(

      {"_id": "test"}

      ,

      {"_id":"test"}

      ,

      {upsert: true}

      );
      > db.chatsessions.find();

      { "_id" : "test" }

      <_id": "test1"},{"_id":"test1","$set":{"key": "value"}},

      {upsert: true}

      );
      Modifiers and non-modifiers cannot be mixed
      > db.chatsessions.update(

      {"_id": "test1"}

      ,{"$set":{"_id": "test1", "key": "value"}},

      {upsert: true}

      );
      Mod on _id not allowed
      >

      I think that the error "Modifiers and non-modifiers cannot be mixed" shouldn't occur in case of _id.
      In case that an object exists already, _id should be ignored.

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            gf gf
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: