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

Support for $elemMatch inside $in

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Backlog
    • Major - P3
    • Resolution: Unresolved
    • None
    • None
    • Querying
    • None
    • Query Optimization

    Description

      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

      Attachments

        Issue Links

          Activity

            People

              backlog-query-optimization Backlog - Query Optimization
              mdelamere Michael Delamere
              Votes:
              7 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

                Created:
                Updated: