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

Dot notation updates with arrays can lead to nonsensical results

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      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

              Assignee:
              backlog-query-optimization Backlog - Query Optimization
              Reporter:
              ross.lawley Ross Lawley
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: