Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Types] sort by $meta textScore is not allowed #11867

Closed
2 tasks done
Jule- opened this issue Jun 1, 2022 · 1 comment · Fixed by #11370
Closed
2 tasks done

[Types] sort by $meta textScore is not allowed #11867

Jule- opened this issue Jun 1, 2022 · 1 comment · Fixed by #11370
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.

Comments

@Jule-
Copy link

Jule- commented Jun 1, 2022

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.

@Uzlopak
Copy link
Collaborator

Uzlopak commented Jun 2, 2022

Should be fixed with PR #11370

@Uzlopak Uzlopak linked a pull request Jun 2, 2022 that will close this issue
19 tasks
@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants