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

Allow queries with $expr/$in to use indexes.

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution

      This query:

      find({$expr: { $in: ["$_id", [1, 2]]}})
      

      ... doesn't use an index.

      If I expand the $in to $or and $eq, though, it uses the index:

      find({$expr: { $or: [{$eq: ["$_id", 1]}, {$eq: ["$_id", 2]}]}})
      

      This seems like something the server could gainfully do internally to avoid a collection scan.

            Assignee:
            Unassigned Unassigned
            Reporter:
            felipe.gasper@mongodb.com Felipe Gasper
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: