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

update accepts true or an options document

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Won't Fix
    • Affects Version/s: 4.0.6
    • Fix Version/s: None
    • Component/s: Shell
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      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
    • Sprint:
      Dev Tools 2019-05-20

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: