You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the latest version (2.2.1) a schema that contains a subdocument (in my case with the _id field turned off) results in an empty object being applied to that field when it is empty in the database.
@ajwootto I think I'm experiencing the same issue, but 2.2.1 is the first version of this plugin that I've used, so the expected behavior is unclear to me. What was the last version where this worked for you?
The fix for #30 definitely resolved the case below, where default: undefined is explicitly set in the schema:
Without default: undefined, we get empty objects with a new generated ObjectID. In your case, you explicitly remove the _id, so simply get an empty object.
The Mongoose docs say that subdocuments default to undefined, and I think it would make sense to match that expectation in this plugin. I think the behavior was changed by the fix for #18 - by trying to include projected defaults, it results in every undefined subdocument now being an actual object. I am not sure how to match the default Mongoose behavior without breaking the projection support in the lean-defaults plugin.
Describe the bug
Seems to be similar to #30
In the latest version (2.2.1) a schema that contains a subdocument (in my case with the _id field turned off) results in an empty object being applied to that field when it is empty in the database.
To Reproduce
Output of the log is
Expected behavior
I would have expected the output to simply not include the "children" field, which was the behaviour in previous versions.
Additional context
Mongoose version: 7.5.0
Node version: 18.16.0
The text was updated successfully, but these errors were encountered: