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

Provide a way to find out if $addToSet caused a change to the list

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Duplicate
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • Write Ops
    • None

    Description

      Using $addToSet there is no way to find if the add changed the list. I would have though that the updatedExisting field in getLastError would reflect if a change was made or not but it doesn't seem to do that.

      > db.set.insert(

      { set : ['1','2','3'], _id : "123" }

      );
      > db.set.update({_id:"123"},{"$addToSet":{ set: '4'}}); db.runCommand("getlasterror");

      { "err" : null, "updatedExisting" : true, "n" : 1, "ok" : 1 }

      > db.set.update({_id:"123"},{"$addToSet":{ set: '4'}}); db.runCommand("getlasterror");
      { "err" : null, "updatedExisting" : true, "n" : 1, "ok" : 1

      I'm not sure what the best option here is but it would be very useful to know.

      Attachments

        Activity

          People

            Unassigned Unassigned
            bdarfler Benjamin Darfler
            Votes:
            7 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: