$elemMatch is normally used when the array values are documents. But can it be used when the array values are not documents? And what is the syntax? Experimentation shows that this seems to be possible but with limitations.
This JIRA requests:
1. That use of $elemMatch with array values that are not documents be properly supported and documented
2. That $elemMatch with array values that are not documents support the full range of query operators
Here's a simple example of a non-trivial query that is not currently supported.
Given the following collection:
We can find documents where a contains a multiple of 2 as follows:
Or similarly, a multiple of 3:
But we can't find documents where a contains a number that is a multiple of 2 and not a multiple of 3.
The syntax wouldn't have to be exactly like that, just that there needs to be a way to specify multiple conditions that must all be matched by the same array item when that item is not a document.
The motivation for this JIRA ticket is that the LINQ implementation in the C# driver needs to be able to translate C# where clauses to equivalent MongoDB queries. The above example of finding multiples 2 that are not multiples of 3 would look like this in LINQ:
How would this be expressed in the MongoDB query language?