-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
None
-
Query Optimization
We allow $elemMatch clauses inside an $all as shown below, but we reject this for $in. We should allow an $in-$elemMatch query which says "the document must match one of these $elemMatch clauses".
Original Description
Hello,
In mongodb I can query with either $and or $or which is important for deciding whether all elements need to match or just one.
Looking at the following example provided in the mongob-docs:
db.inventory.find( { qty: { $all: [ { "$elemMatch" : { size: "M", num: { $gt: 50} } }, { "$elemMatch" : { num : 100, color: "green" } } ] } } )
you can see that one can specify - in combination with $elemMatch - that all ($all) the subqueries must match.
What I would like to do is to say that only one of these has to match, which is important for doing certain types of search-queries. I noticed though, that although for $and there is the alternative $or, this does not seem to exist for $all. I would therefore like to request something like a $any keyword which behaves like $or, but can be used like $all.
I think this is quite an important issue and shouldn't be to hard to implement - or is it?
Thanks for the great work.
Best regards,
Michael
- is duplicated by
-
SERVER-3544 support $elemMatch with $in
- Closed
- related to
-
SERVER-589 query $operators should be composable
- Backlog