Currently $elemMatch only supports array values, so queries such as {foo: {$elemMatch:
{a:1, b:2}}} will match {foo:[
{a:1, b:2, c:3}]}, but not {foo: {a:1, b:2, c:3}}. I know this can be easily done by query
{'foo.a':1, 'foo.b':2}, but this behavior is inconsistent with other query operations; e.g.
{a:1}will match both
{a:[1]}and
{a:1}.
I'm currently writing a DSL for mongo, and I find it hard to explain this inconsistency to users. But I don't know if changing this will affect query optimizer.
- duplicates
-
SERVER-6050 Consider allowing $elemMatch applied to non arrays
- Closed