Populate with select on nested field returns extra sub-field of array type. #13003
Closed
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
6.9.0
Node.js version
16.13.1
MongoDB server version
6.0.3
Typescript version (if applicable)
4.1.3
Description
A parent schema contains a reference to a child schema. The child schema contains a nested field, with a string property and an array property. When populating a parent and selecting the nested string property, the array property is also included, with empty contents.
Steps to Reproduce
Example code:
This prints:
Note that the
bar
field is included, unexpectedly. If I populate thebar
array in the child document, such as:Then I still get an empty
bar
array in the populated parent document.I don't encounter the same problem when
bar
is a simple string property instead of an array of objects, e.g.:Using the original example with Mongoose 5.11.5 I get the expected result:
Expected Behavior
The populated
Parent
document contains only theproperties.foo
field, similar to with mongoose 5.x.The text was updated successfully, but these errors were encountered: