Allow $match or $sort stages that follow the $search stage to use MongoDB native indexes
Currently, if there are $match
or $sort
stages that follow the $search
stage, then those $match
and $sort
stages are unable to use MongoDB's native indexes on the fields being matched/sorted.
While the documentation recommends 1) designing your $search
query so that all necessary filtering occurs in the $search
stage which removes the need for a $match
stage and 2) instead of using a $sort
stage, using the $near
operator to sort documents based on a numeric
, date
, or geo
field, such changes are not always feasible depending on the use-case. In such instances, having a $match
and $sort
after the $search
can be unavoidable; and in those instances, it would be ideal for those $match
and $sort
stages to be able to use MongoDB native indexes on the fields being matched/sorted.
This is a feature request to introduce the functionality which will allow $match
or $sort
stages that follow the $search
stage to use MongoDB native indexes on the fields being matched/sorted. That way, the $search
stage can utilize the Atlas Search index, while the $match
/$sort
stages that follow it can use the MongoDB native indexes, making the query more performant.
The spirit of this request is to provide faster sorted results with Atlas Search. Efficient sorting of results when using Atlas Search is an important use-case to us and that we are proactively exploring what features we can provide in this regard. After reviewing with the engineering team, we've determined that this particular approach will not provide the intended benefits so we will not be pursuing it. Please follow Faster Sorting with Atlas Search for future developments.