Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-16663

Clarify use of $in predicate in ESR querying guidelines

      This documentation page says:

      -$in can be an equality operator or a range operator.
      --When $in is used alone, it is an equality operator that performs a series of equality matches.
      --When $in is used with .sort(), $in can act like a range operator.
      

      A few people have found this confusing. To clarify: when $in is used with a sort(), there are two cases. For a small $in list (less than 200 elements) the $in can be "exploded" and treated as a bunch of point lookups in the index which are merged in the correct sort order.

      For large $in lists (when a sort is present), this optimization is not possible, and the index cannot provide the sort. However, saying $in "acts" as a range predicate is a bit misleading, since it's still a bunch of equality predicates. What I would instead say is that from an ESR perspective, a large $in should be ordered like a range predicate, rather than an equality one. This is a very subtle distinction, but I think worth clarifying in the docs.

            Assignee:
            jason.price@mongodb.com Jason Price
            Reporter:
            ian.boros@mongodb.com Ian Boros
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              1 week, 4 days ago