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

update accepts true or an options document

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 4.0.6
    • Component/s: Shell
    • Labels:
      None
    • ALL
    • Hide

      create a database that has a collection called user_data (name doesnt matter)

      execute command:

      db.user_data.updateOne({"entity_id":"9AQX8AVP1F6QEX4IANCD","data_id":"permissions"},{'$addToSet':{"value":"admin"}},true)
      

      you will get

      { "acknowledged" : true, "matchedCount" : 0, "modifiedCount" : 0 }
      

      execute command:

      db.user_data.update({"entity_id":"9AQX8AVP1F6QEX4IANCD","data_id":"permissions"},{'$addToSet':{"value":"admin"}},true)
      

      you will get

      WriteResult({
       "nMatched" : 0,
       "nUpserted" : 1,
       "nModified" : 0,
       "_id" : ObjectId("5c7f1e7b66535aa5d0c469d7")
      })
      

      i would expect updateOne to do the same as update

      Show
      create a database that has a collection called user_data (name doesnt matter) execute command: db.user_data.updateOne({"entity_id":"9AQX8AVP1F6QEX4IANCD","data_id":"permissions"},{'$addToSet':{"value":"admin"}},true) you will get { "acknowledged" : true, "matchedCount" : 0, "modifiedCount" : 0 } execute command: db.user_data.update({"entity_id":"9AQX8AVP1F6QEX4IANCD","data_id":"permissions"},{'$addToSet':{"value":"admin"}},true) you will get WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : ObjectId("5c7f1e7b66535aa5d0c469d7") }) i would expect updateOne to do the same as update
    • Dev Tools 2019-05-20

      for my project i needed to upsert into a set of values. i noticed that upserting didnt work when i was using updateOne, but it worked when i used update. this was done in the terminal, running mongodb shell 4.0.6.

            Assignee:
            gabriel.russell@mongodb.com Gabriel Russell (Inactive)
            Reporter:
            fredlllll Frederik Gelder
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: