-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Using default value on sub documents does not work as expected #14445
Comments
Found and even bigger problem with this behaviour where the sub document gets updated in the database by just updating any other property on the document. Look at the example below. By just changing the name, the sub document gets changed from the default empty object to
|
I'm seeing the same issue, a field of type |
Downgrading from 8.2.2 to 8.2.1 seems to solve this issue. |
fix(document): make update minimization unset property rather than setting to null
Prerequisites
Mongoose version
8.2.2
Node.js version
20.11.1
MongoDB server version
6.3.0
Typescript version (if applicable)
No response
Description
We still don't get the correct behaviour with sub documents in our schema with mongoose 8. This it related to #14420 and the fix in #14437 did not resolve the issue.
When setting the nested document to an empty object, this get saved as
null
in the database. Fetching the document from the database will not fallback to the default empty object.When setting the nested document to
undefined
, fetching the document from the database will return the default empty object.This requires us to manually handle all nested paths to make sure that the values are both saved correct and use the correct return values.
Steps to Reproduce
Expected Behavior
We expect the document to have the same nested value both after save and when fetching the document form the database. And we expect the value to resolve to the default empty object (especially when explicitly setting the value to the default value)
The text was updated successfully, but these errors were encountered: