Closed ghendo closed 2 years ago
We don't support embedding a sort into a $search
stage, so you'll need to use a separate $sort
stage. The Atlas Search Team is currently working on improving the performance of these types of queries so that they will run faster in the future.
Hi, based on conversations with some Atlas's Engineers, you can sort affected documents by using the "$near
" operator in "$search
" stage, this due to the performance is degraded when you use the "$sort
" stage after "$search
", same as with the "$count
" stage, if you want to get the affected documents count you can use the "$searchmeta
" stage or use the variable "$SEARCH_META
" in a "$projection
" stage or "$addfield
" stage. I hope this can help to solve some future questions.
By the way... Good work @dgolub!! 👍🏽
Can a sort be included in the search rather than add a stage?