-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
6.3.5
Node.js version
16.14.2
MongoDB server version
4.2.3
Description
It is not possible to handle a text index search with sorting on the meta score like described in the MongoDB documentation: https://www.mongodb.com/docs/manual/core/text-search-operators/#query-framework
db.stores.find(
{ $text: { $search: "coffee shop cake" } },
{ score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } )
Typescript is complaining:
Type '{ score: { $meta: string; }; }' is not assignable to type 'string | { [key: string]: SortOrder; }'.
Types of property 'score' are incompatible.
Type '{ $meta: string; }' is not assignable to type 'SortOrder | undefined'.ts(2345)
Steps to Reproduce
Mongoose typings should allow doing:
const stores = await Store.find(
{ $text: { $search: "coffee shop cake" } },
{ score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } )Expected Behavior
No Typescript error.
Metadata
Metadata
Assignees
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.