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

Query on key-val array using $all and $elemMatch does not seem to correctly use indexes

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.7
    • Component/s: Querying
    • Labels:
      None
    • ALL

      Having a collection with elements with a 'tags' array, where each element in the array is {k:<key>, v:<value>}, with an index {'tags.k': 1, 'tags.v': 1}

      A query of the form
      db.coll.find({tags : { "$elemMatch" : { k : "somekey", v : "somevalue" } } })

      correctly makes use of the index. However, a query like:
      db.coll.find({tags : {$all: [ { "$elemMatch" : { k : "somekey", v : "somevalue" } } ] } })

      does not make use of the index and produces a full scan
      (note: the use of $all is to allow search matching on more than one tag)

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            pep.martinez Pep Martinez
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: