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

Optimize $or queries to perform like $in if all clauses are on the same field

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

      For performance reasons, you would generally decide to use $in in scenarios where they apply over $or.

      However, some scenarios apply that you would be forced to use a $or in order to add more complex clauses or ranges to your query. For something like find all values of a where a > 10 and a < 20 or a > 30 and a < 50, you would be forced to use a $or query even though the only field being used in the index is a.

      $or should be able to detect when it does not need to run as multiple queries and perhaps handle single field cases like this in a performant way.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            osmar.olivo Osmar Olivo
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: