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

Query using _id index doesn't populate indexKey metadata field

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • ALL

      Steps to reproduce:

       

      > db.c.insert({_id: 1, a: "foo"})
      > db.c.createIndex({a: 1})
      > db.c.find({a: "foo"}, {key: {$meta: "indexKey"}})
      [ { _id: 1, a: 'foo', key: { a: 'foo' } } ]
      > db.c.find({_id: 1}, {key: {$meta: "indexKey"}})
      [ { _id: 1, a: 'foo' } ]

      I would have expected:

       

      > db.c.find({_id: 1}, {key: {$meta: "indexKey"}})
      [ { _id: 1, a: 'foo', key: { _id: 1 } } ] 
      > db.c.find({_id: 1}, {key: {$meta: "indexKey"}}).explain().queryPlanner
      {
        namespace: 'test.c',
        indexFilterSet: false,
        parsedQuery: { _id: { '$eq': 1 } },
        queryHash: '58F0F49D',
        planCacheKey: '0028A5F4',
        maxIndexedOrSolutionsReached: false,
        maxIndexedAndSolutionsReached: false,
        maxScansToExplodeReached: false,
        winningPlan: {
          stage: 'PROJECTION_DEFAULT',
          transformBy: { key: { '$meta': 'indexKey' } },
          inputStage: { stage: 'IDHACK' }
        },
        rejectedPlans: []
      } 

      One theory is that IDHACK is not setting the metadata field properly, but this requires further investigation.

       

       

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            ben.shteinfeld@mongodb.com Ben Shteinfeld
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: