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

Should {a:[[]]} match {a: {$size:0}}

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Query Optimization
    • Query Optimization 2021-05-03

      Currently it doesn't, but it seems like it should, since our general semantics would check if any elem in an array matches the predicate. It is seems especially odd since we already do traverse arrays in the path in some cases for size.

      > db.arr_stress.insert({a:[[]]})
      WriteResult({ "nInserted" : 1 })
      > db.arr_stress.insert({a:[{b:[]}]})
      WriteResult({ "nInserted" : 1 })
      
      > db.arr_stress.find({a:{$size:0}})
      > db.arr_stress.find({'a.b':{$size:0}})
      { "_id" : ObjectId("604f86bbe25682f5583b49d0"), "a" : [ { "b" : [ ] } ] }
      
      > db.arr_stress.find({a:[]})
      { "_id" : ObjectId("604f8628e25682f5583b49cf"), "a" : [ [ ] ] }
      > db.arr_stress.find({'a.b':[]})
      { "_id" : ObjectId("604f86bbe25682f5583b49d0"), "a" : [ { "b" : [ ] } ] }
      

      Making {a: {$size: 0}} match here would mean that it is now equivalent to {a:[]}. I'm not sure if that is an argument for or against changing it, but it seemed worth noting.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: