We've a node.js + mongoose app running on Ubuntu linux servers spun on DigitalOcean VPS.
One of our mongoose queries have a text index with the following operators:
and looks like this:
db.sampleCollection.find({
$text: {
$search: userInput
},
$lte: {
expired: (new Date()).addDays(30)
},
$limit: 9,
$orderby: {
postedAt: -1
}
})
which throws this error:
unknown top level operator: $orderby
Solutions already considered:
- Mongoose uses $set by default, however we're not using that operator in our query
- This solution considers aggregation, however we need it for find function
- This solution seems to be for array fields, however we need solution for non-array indexes
- We're not mixing operators, as said in this solution
Need inputs on how to fix this.