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

New FilterQuery type (from 8.6.0) disallows $expr at the query root (type error) #14841

Closed
2 tasks done
Anton-Plagemann opened this issue Aug 29, 2024 · 1 comment · Fixed by #14845
Closed
2 tasks done
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@Anton-Plagemann
Copy link

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.8.0

Node.js version

20.15.0

MongoDB server version

7.0.9

Typescript version (if applicable)

5.5.4

Description

Starting from mongoose 8.6.0, this raises a type error:

import type { FilterQuery } from "mongoose";

const filter: FilterQuery<{ owners: string[] }> = {
  $expr: { $lt: [{ $size: "$owners" }, 10] },
};
Object literal may only specify known properties, and '$expr' does not exist in type 'FilterQuery<{ owners: string[]; }>'.ts(2353)

I think its related to the changes from #14764.

Steps to Reproduce

Install mentioned versions and create a file with the snippet.

Expected Behavior

No type errors, as its a valid MongoDB query.

@Anton-Plagemann Anton-Plagemann changed the title New RootQuerySelector (from 8.6.0) dissallows $expr at the query root (type error) New RootQuerySelector (from 8.6.0) disallows $expr at the query root (type error) Aug 29, 2024
@Anton-Plagemann Anton-Plagemann changed the title New RootQuerySelector (from 8.6.0) disallows $expr at the query root (type error) New FilterQuery type (from 8.6.0) disallows $expr at the query root (type error) Aug 29, 2024
@vkarpov15 vkarpov15 added this to the 8.6.1 milestone Aug 29, 2024
@vkarpov15 vkarpov15 added the typescript Types or Types-test related issue / Pull Request label Aug 29, 2024
@sapirMalAccessibe
Copy link

I’m also having an issue with upgrading to 8.6 because it doesn’t recognize the field key in the filter of an updateMany query, which is part of the model.

await this.updateMany({ url: { $in: urlsToCheck } }, { $set: { lastCheckAt: new Date() } });

error TS2353: Object literal may only specify known properties, and 'url' does not exist in type 'RootFilterQuery'.

vkarpov15 added a commit that referenced this issue Sep 3, 2024
types(query): add $expr to RootQuerySelector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants