-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Model.hydrate() should work with subdocument array projection #14680
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
vkarpov15
added
the
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
label
Jun 24, 2024
vkarpov15
added a commit
that referenced
this issue
Jun 25, 2024
fix(projection): handle projections on arrays in `Model.hydrate()` projection option
This was referenced Jul 16, 2024
Closed
This was referenced Jul 17, 2024
This was referenced Jul 17, 2024
This was referenced Aug 21, 2024
This was referenced Aug 23, 2024
This was referenced Aug 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Mongoose version
8.4.3
Node.js version
20.14.0
MongoDB server version
7.0.11
Typescript version (if applicable)
No response
Description
When calling
Model.hydrate()
with a schema that includes a subdocument array, and passing a projection as the second argument, this projection does not get applied correctly to the subdocuments. The result is an array of empty objects in the subdocument array field.I believe this might be related to the behavior of
applyInclusiveProjection()
, which is recursive and will call itself with the subdocument array as the first argument.Steps to Reproduce
The following snippet will reproduce this behavior:
The result is an object that looks like:
{ testArray: [ {} ] }
The first level projection is applied correctly, but all keys in the subdocument have been deleted.
Expected Behavior
If a schema with an array of subdocuments is passed, the projection should be applied as expected, or throw an error if unsupported.
The text was updated successfully, but these errors were encountered: