|
As I said, I'm not sure it is a bug, just a somewhat surprizing quirk in our language. I wasn't expecting it to be fixed immediately, since that would be a breaking semantic change, instead I filed it to record something else to add to the list of things to think about when designing MQL 2.0 (or 1.N+1 if we just add things).
Maybe I'm wrong, but I feel like $size is the only operator that only does partial implicit array traversal (note that it does do some traversal in the {'a.b': {$size: 0}} case, so I would disagree that it doesn't do traversal). At least in my mental model, $elemMatch does do traversal, and applies the inner predicate on the traversed nodes.
Another way to look at this is that we need an "anti-$elemMatch" (strawman name: $fieldMatch). Then we could say that {$size:0}'s current behavior is the same as {$fieldMatch: []}. It would then be an open question whether we would want $size to continue to have the implicit $fieldMatch behavior (I could certainly see justification for it), or if we want to allow users to use it to match arrays-of-arrays (which admittedly aren't well supported by the rest of our query language,)
|