Skip to content

Type Safety not in place for operators in find() query #16062

@debiprasadmishra50

Description

@debiprasadmishra50

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.23.0

Node.js version

24.12.0

MongoDB server version

8.0.19

Typescript version (if applicable)

5.4.5

Description

export type Condition<T> = T | QuerySelector<T | any> | any;
in query.d.ts literally acccepts any due to which the intellisense fails and it accepts nonsense queries like this

const data = await this.movieModel.find(
      { $and: [{ runtime: { $wrong: 100 } }] }, // ❌ there is no $wrong operator
      { "awards.nominations": 1 }
    );

And also, there is no autocompletion suggestions as well.

Steps to Reproduce

I used NestJS to produce this

  1. Create a Schema
  2. Inject Model like this
    @InjectModel(Movie.name) private readonly movieModel: Model<Movie>,
  3. Write a query like this
const data = await this.movieModel.find(
      { $and: [{ runtime: { $wrong: 100 } }] }, // ❌ there is no $wrong operator
      { "awards.nominations": 1 }
    );

Expected Behavior

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions