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

Schema.index text weight types #10586

Closed
AlexZeDim opened this issue Aug 21, 2021 · 9 comments
Closed

Schema.index text weight types #10586

AlexZeDim opened this issue Aug 21, 2021 · 9 comments
Milestone

Comments

@AlexZeDim
Copy link

Versions of package.json and tsconfig.json:

- "mongoose": "5.13.7",
- "typescript": "4.2.4",

Also, I am using Node.js: 16.0.N with Nestjs (8.0) but I guess it doesn't matter since the problem isn't in there.

I'd to ask a question about text indexes and probably report a bug.

I have a problem with build a text index, with the following syntax:

RealmsSchema.index(
  {
    slug: 'text',
    name: 'text',
    name_locale: 'text',
    slug_locale: 'text',
    ticker: 'text',
    region: 'text',
    locale: 'text',
  },
  {
      weights:
        {
          slug: 10,
          name: 1,
          slug_locale: 1,
          name_locale: 1,
          ticker: 3,
          region: 1,
          locale: 1,
        },
    name: 'SQ',
  },
);

Since 5.13.7 version of mongoose gives me the following type error via IDE:
image

But before updating to mongoose 5.13 I was using 5.12,N and it was actually fine. I have tried various syntaxes according to *.d.ts files inside the mongoose itself, with using of `collection object and so on, but it still gives me errors. So the question is, is it a bug? How exactly should I build text indexes with custom weight on the fields right now?

image

@hasezoey
Copy link
Collaborator

could you provide what version of mongodb / @types/mongodb is installed? because the mongoose Index types extend from the mongodb ones in recent 5.13.x releases

note: if 4.x is installed, try downgrading to 3.6.x (both mongodb and @types/mongodb)

@rlawisch
Copy link

I've just had a similar problem with mongoose 5.13.7: when sending { unique: true } in IndexOptions, an error was raised because there were no MongoDB.IndexOption type to be extended. The NPM resolved dependency version for @types/mongodb was 3.6.20.

@hasezoey
Copy link
Collaborator

@rlawisch could you either open another issue or provide the code where you tried to add this option and the error?

@rlawisch
Copy link

rlawisch commented Aug 23, 2021

Sure, I will document it more thoroughly and open an issue properly
Update: opened #10590

@vkarpov15
Copy link
Collaborator

@rlawisch this looks like a bug on your end, you're specifying weights as a sub-option of collation, which is incorrect: https://docs.mongodb.com/manual/tutorial/control-results-of-text-search/#control-search-results-with-weights

@rlawisch
Copy link

@vkarpov15 I think you mean to mention @AlexZeDim

@AlexZeDim
Copy link
Author

AlexZeDim commented Aug 23, 2021

@vkarpov15 can it be reopened, please?

Guess you missed some descriptions from my issue. In 5.13.7 weight in part has somehow become part of the collation at
mongodb/index.d.ts:
image

And the original syntax from the beginning was:

image

@hasezoey mongodb version is 4.2.3 community, and I don't have @types/mongodb since mongoose has its own types.

@hasezoey
Copy link
Collaborator

@hasezoey mongodb version is 4.2.3 community, and I don't have @types/mongodb since mongoose has its own types.

sorry if this was not clear, i meant what mongodb driver version was installed and used
and mongoose depends on @types/mongodb, so i asked what version was installed "implicitly"

@AlexZeDim
Copy link
Author

@hasezoey
image

@vkarpov15 vkarpov15 reopened this Aug 23, 2021
@vkarpov15 vkarpov15 added this to the 5.13.9 milestone Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants