Is $IN operator able to use Index?

It should.

Please provide the output of:

db.ConveyorReceipt.getIndexes()
> c.getIndexes()
[
  { v: 2, key: { _id: 1 }, name: '_id_' },
  { v: 2, key: { a: 1 }, name: 'a_1', background: false }
]
> c.find( { a : { '$in' : [ 2 , 3 ]}}).explain().queryPlanner.winningPlan
{
  stage: 'FETCH',
  inputStage: {
    stage: 'IXSCAN',
    keyPattern: { a: 1 },
    indexName: 'a_1',
    isMultiKey: false,
    multiKeyPaths: { a: [] },
    isUnique: false,
    isSparse: false,
    isPartial: false,
    indexVersion: 2,
    direction: 'forward',
    indexBounds: { a: [Array] }
  }
}
1 Like