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

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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Querying
    • Labels:
      None
    • Sprint:
      Query Optimization 2021-05-03

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            backlog-query-optimization Backlog - Query Optimization
            Reporter:
            redbeard0531 Mathias Stearn
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated: