-
Type: Improvement
-
Resolution: Unresolved
-
Priority: 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.