mongodb-labs / mongo-csharp-search

C# driver extension providing support for Atlas Search
Apache License 2.0
17 stars 1 forks source link

Sort in Search #11

Closed ghendo closed 2 years ago

ghendo commented 2 years ago

Can a sort be included in the search rather than add a stage?

dgolub commented 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.

ggaldamesd commented 1 year ago

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!! 👍🏽