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

Inconsistent treatment of numerical path components between query and update

    • Query Optimization
    • ALL

      In the query language, when a numerical path component is used to select an element of an array, elements are only selected if the numerical path component matches their exact fieldname:

      > db.c.insert({_id: 0, a: [0]})
      WriteResult({ "nInserted" : 1 })
      > db.c.find({"a.00": 0})
      > db.c.find({"a.0": 0})
      { "_id" : 0, "a" : [ 0 ] }
      

      In the update language, a numerical path components is parsed as an unsigned base 10 integer n, and we select the nth array element:

      > db.c.insert({_id: 0, a: [0]})
      WriteResult({ "nInserted" : 1 })
      > db.c.update({_id: 0}, {$set: {"a.00": 1}})
      WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
      > db.c.find()
      { "_id" : 0, "a" : [ 1 ] }
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: