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

$all/$elemMatch doesn't use index correctly

    • Query

      I have a collection called PartOffer with a multikey called 'p'. Typical PartOffer looks like:

      {title:"My offer", p:{carFuel:9023, engine:232}}
      

      I created an index on p:

      db.PartOffer.ensureIndex({p:1})
      

      But when using dot notation to find all offers depending on a property inside p, then the index is not used:

      > db.PartOffer.find({"p.carFuel":9086}).explain()
      {
              "cursor" : "BasicCursor",
              "nscanned" : 65424,
              "nscannedObjects" : 65424,
              "n" : 1139,
              "millis" : 126,
              "indexBounds" : {
      
              }
      }
      

      But when not using dot notation, the index is used:

      > db.PartOffer.find({p:{carFuel:9086}}).explain()
      {
              "cursor" : "BtreeCursor p_1",
              "nscanned" : 21,
              "nscannedObjects" : 21,
              "n" : 21,
              "millis" : 0,
              "indexBounds" : {
                      "p" : [
                              [
                                      {
                                              "carFuel" : 9086
                                      },
                                      {
                                              "carFuel" : 9086
                                      }
                              ]
                      ]
              }
      }
      

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            klu2 Klaus Lehner
            Votes:
            11 Vote for this issue
            Watchers:
            19 Start watching this issue

              Created:
              Updated:
              Resolved: