Skip to content

MongoBaseQueryOptions no longer supports arbitrary options #15643

@Gonyoda

Description

@Gonyoda

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

Node.js version

22.16.0

MongoDB server version

8

Typescript version (if applicable)

No response

Description

A change made to the definition of MongoBaseQueryOptions in this PR for 8.17 seems to have inadvertently left out the ability to pass arbitrary options into various model methods. Some methods use QueryOption which does allow arbitrary options while many others, like countDocuments, use MongoBaseQueryOptions which no longer allows arbitrary options.

Suggested change to MongooseBaseQueryOptions:

type MongooseBaseQueryOptions<DocType = unknown> = Pick<QueryOptions<DocType>, MongooseBaseQueryOptionKeys> & {
    [other: string]: any;
  };

Steps to Reproduce

Usage code:

type OurCustomOptionsWhereWeHavePreHooksSetupToHandle {
   includeDeleted?: boolean;
}

...
        this.model
          .countDocuments(filter, {
            includeDeleted: options?.includeDeleted ?? false,
          });

includeDeleted is no longer allowed.

Object literal may only specify known properties, and 'includeDeleted' does not exist in type 'CountOptions & MongooseBaseQueryOptions<TReadEntity> & Abortable'.ts(2353)

Expected Behavior

We should be able to pass arbitrary options into various model query method.

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