'MongoDB sort the query by the first field, then by the second

So I'm trying to sort my query:

await Content.find({
    $text: {$search: `\"${query}\"`},
}

It querys in the title, text and author of a document. Basically, I want to order it by the fields, so that if the searched word is in the title field it is on the first place and so on with the author and text.

Is this even possible with mongodb or do I have to do this on the Javascript side?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source