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
Do you want to request a feature or report a bug?
Could be interpreted both ways but I'd label it as a bug.
What is the current behavior?
When creating a virtual field referencing an array of other documents, the population of the field works inconsistently. The resulting values will vary between an array filled with users, an empty array and undefined. This is inconsistent and will cause issues and/or unnecessary type checks.
If the current behavior is a bug, please provide the steps to reproduce.
As an example we will attempt to populate all children of a user document which are user documents themselves. The schema will be complemented with an array called childIds containing all children ids and a virtual called children which references the user schema.
Afterwards we will define a scenario where Joe has two children called John and Jane. When we find and populate all users we will receive three user objects with two of them containing an empty array at the children field and one containing an array with the two previous users. When we find and populate the two users without children however, we will receive those two users without the children field since it is left empty.
What is the expected behavior?
I expect that, since I define it to be an array, the virtual field is always filled as an array when populated even when empty.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
vkarpov15
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
labels
Oct 23, 2019
Do you want to request a feature or report a bug?
Could be interpreted both ways but I'd label it as a bug.
What is the current behavior?
When creating a virtual field referencing an array of other documents, the population of the field works inconsistently. The resulting values will vary between an array filled with users, an empty array and undefined. This is inconsistent and will cause issues and/or unnecessary type checks.
If the current behavior is a bug, please provide the steps to reproduce.
As an example we will attempt to populate all children of a user document which are user documents themselves. The schema will be complemented with an array called
childIds
containing all children ids and a virtual calledchildren
which references the user schema.Afterwards we will define a scenario where Joe has two children called John and Jane. When we find and populate all users we will receive three user objects with two of them containing an empty array at the
children
field and one containing an array with the two previous users. When we find and populate the two users without children however, we will receive those two users without thechildren
field since it is left empty.What is the expected behavior?
I expect that, since I define it to be an array, the virtual field is always filled as an array when populated even when empty.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js: v12.10.0
MongoDB: v4.2.0
Mongoose: v5.7.3
The text was updated successfully, but these errors were encountered: