Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14203

Support for $elemMatch inside $in

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      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

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            mdelamere Michael Delamere
            Votes:
            7 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated: