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

BREAKING CHANGE updating from 8.6.0 to 8.8.2: lean query return full mongoose object type for populated doc instead of FlattenMaps #15047

Open
2 tasks done
nikzanda opened this issue Nov 20, 2024 · 1 comment

Comments

@nikzanda
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

8.8.2

Node.js version

20.10.0

MongoDB server version

6.0.2

Typescript version (if applicable)

5.5.4

Description

In my repository, I have installed version 8.6.0 of Mongoose. After updating to the latest version (8.8.2), I encountered new typing errors: the PopulatedDoc variables are typed as full Mongoose objects instead of FlattenMaps when the query is lean.

Below are some screenshots:

This is the type returned in version 8.6.0:
Image

This is the type returned in version 8.8.2:
Image

Furthermore, for both versions of Mongoose, the linter does not give me any errors when I run child.save(), but at runtime, I get the expected error child.save is not a function.

Image

As you can see from the screenshot, child is actually a normal object of type IChild (or FlattenMaps<...>), so it correctly throws an error when trying to execute child.save(). However, the linter should already be flagging this issue.
Image

Steps to Reproduce

Reproduction link here

Expected Behavior

I expect PopulatedDoc variables to be typed with IChild or FlattenMaps<...> when the query is lean.

Ideally, PopulatedDoc variables should be directly typed with FlattenMaps<...> if the query uses the populate method, and with Types.ObjectId if the query does not use the populate method.

@Makoehle
Copy link

Updating from 8.6.3 to 8.7.1. is already introducing a breaking change when using MongoDB 3.6 which has less valnurbilities than 4.0.

reports maximum wire version 6, but this version of the Node.js Driver requires at least 7 (MongoDB 4.0)\n

This still happens for 8.8.2.

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

2 participants