Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-14287

Update command documentation should describe expected behavior when a multi-update fails

      Description

      Page: https://docs.mongodb.com/manual/reference/command/update/index.html

      Consider the following sequence of commands which results in a document validation failure:

      > db.coll.insertMany([{a: 1, b:1}, {a: 2, b:2}, {a: 3, b:3}, {a:1, b:4}])
      {
             "acknowledged" : true,
             "insertedIds" : [
                     ObjectId("60429200cb07b1d94070d658"),
                     ObjectId("60429200cb07b1d94070d659"),
                     ObjectId("60429200cb07b1d94070d65a")
             ]
      }
       
      > db.coll.createIndex({b: 1})
      {
             "createdCollectionAutomatically" : false,
             "numIndexesBefore" : 1,
             "numIndexesAfter" : 2,
             "ok" : 1
      }
       
      > db.runCommand({collMod: "coll", validator: {a: {$ne: 200}}})
      { "ok" : 1 }
       
      > db.coll.updateMany({}, {$mul: {a: 100}}, {hint: {b: 1}})
                                                                                                                                                                                                                                                                                    
      > db.coll.find()
      {
       "_id": ObjectId("6047934b5921dc2713d2b1e8"),
       "a": 100,
       "b": 1
      }
      {
       "_id": ObjectId("6047934b5921dc2713d2b1e9"),
       "a": 2,
       "b": 2
      }
      {
       "_id": ObjectId("6047934b5921dc2713d2b1ea"),
       "a": 3,
       "b": 3
      }
      {
       "_id": ObjectId("6047934b5921dc2713d2b1eb"),
       "a": 1,
       "b": 4
      }
      

      Note that once a single document fails to update, no other documents are updated. While this is correct behavior, some users may find this surprising as they might expect that the command will continue updating documents after a failure. As such, we should update the documentation of the ‘update’ command to describe what happens in the case of a multi-update that fails.

      Scope of changes

      Impact to Other Docs

      MVP (Work and Date)

      Resources (Scope or Design Docs, Invision, etc.)

            Assignee:
            lauren.tran@mongodb.com Lauren Tran
            Reporter:
            mihai.andrei@mongodb.com Mihai Andrei
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              1 year, 38 weeks ago