[SERVER-14203] Support for $elemMatch inside $in Created: 07/Jun/14 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Michael Delamere | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 7 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Assigned Teams: |
Query Optimization
|
||||||||||||||||
| Participants: | |||||||||||||||||
| Description |
| Comments |
| Comment by David Storch [ 09/Jun/14 ] | ||||||||||||||
|
mdelamere, agreed that we should have parity between $in and $all just as we do between $or and $and. This makes lots of sense. We will take this into account as we plan for future development cycles.
Whoops, good catch! I fixed this in my comment above. | ||||||||||||||
| Comment by Michael Delamere [ 09/Jun/14 ] | ||||||||||||||
|
Hi Dave, Yes that would work (if we replace "products:" with "attributes:"). I would still like to see the $in coming because: a) it is less verbose and I prefer the $in syntax, Obviously there was a reason for creating $all, even although that could have been written as a $and query. I think therefore the same reasons could apply for a $in supporting $elemMatch. As the $or does the trick though, I can see that this will not be on the top of your list. Thanks agan for you time! Best regards, | ||||||||||||||
| Comment by David Storch [ 09/Jun/14 ] | ||||||||||||||
|
Hi Michael, You can write an $or query with $elemMatch clauses using the following syntax:
Our reference pages for $or are here: http://docs.mongodb.org/manual/reference/operator/query/or/. Best, | ||||||||||||||
| Comment by Michael Delamere [ 09/Jun/14 ] | ||||||||||||||
|
Hi, Thanks very much for your response and for editing the ticket accordingly. The idea with the $in sounds excellent and would fit my needs perfectly. I actually tried replacing the $all with $or, but unfortunately that yielded an error. In my concrete case, this works:
But when I replaced the $all with $or I got:
Thanks again and best regards, | ||||||||||||||
| Comment by David Storch [ 09/Jun/14 ] | ||||||||||||||
|
Hi mdelamere, Thanks for the feature request! There is something quite similar to the hypothetical "$any" operator you describe. It's called $in and is documented here: http://docs.mongodb.org/manual/reference/operator/query/in/. Here is an example $in query:
However, you are correct that currently it is illegal to nest $elemMatch queries inside an $in (even though you can nest $elemMatch inside an $all). I'm going to change the title and description of this ticket to be about supporting $elemMatch within an $in query. This would allow you to write a query like this:
The $in operator is syntactic sugar for $or, so you can get the same logical result as the currently unsupported $in-$elemMatch query using an $or:
I'm going to reformat this ticket to be about supporting $elemMatch under $in and mark it for triage. Thanks, |