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

Dot notation updates with arrays can lead to nonsensical results

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • None
    • None
    • None
    • None
    • ALL
    • Hide

      Enterprise test> db.dropDatabase()
      Enterprise test> db.test.insert({_id: 1, arr_a: [1, 3]});
      Enterprise test> db.test.insert({_id: 2, arr_a: [1, 3]});
      Enterprise test> db.test.updateOne({_id: 1}, {$set: {"arr_a.0": 2}});    
      Enterprise test> db.test.updateOne({_id: 2}, [{$set: {"arr_a.0": 2}}]);
      Enterprise test> db.test.find()
      [
        { _id: 1, arr_a: [ 2, 3 ] },
        { _id: 2, arr_a: [ { '0': 2 }, { '0': 2 } ] }
      ]
      

      Show
      Enterprise test> db.dropDatabase() Enterprise test> db.test.insert({_id: 1, arr_a: [1, 3]}); Enterprise test> db.test.insert({_id: 2, arr_a: [1, 3]}); Enterprise test> db.test.updateOne({_id: 1}, {$set: {"arr_a.0": 2}}); Enterprise test> db.test.updateOne({_id: 2}, [{$set: {"arr_a.0": 2}}]); Enterprise test> db.test.find() [ { _id: 1, arr_a: [ 2, 3 ] }, { _id: 2, arr_a: [ { '0': 2 }, { '0': 2 } ] } ]

    Description

      The documentation isn't clear that dot notation behaviour with arrays using $set provides very different results than using $set with arrays.

      The behaviour is surprising.

      Attachments

        Issue Links

          Activity

            People

              backlog-query-optimization Backlog - Query Optimization
              ross@mongodb.com Ross Lawley
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: