Text search and order by MongoDB

We use MongoDB text search, which still works great. However, we also want to indicate the order of the results, for example:

db.items.runCommand("text", {search: "\"test item\"", "$orderby" : { votes : 1 }}); 

This is done, but it is not sorted by vote, it is still sorted by result.

Does anyone know how to do this?

Thanks!

+2
source share
1 answer

The MongoDB "text" command does not support custom sorting, so you have to sort the votes results in your own code.

Supported options are listed here .

+3
source

Source: https://habr.com/ru/post/944034/


All Articles