Unexpected population of virtual with match() function in an embedded subdocument array #14494
Closed
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
8.2.1
Node.js version
20.5.1
MongoDB server version
6.3.0
Typescript version (if applicable)
No response
Description
Populating a virtual with a match() function in an embedded subdocument array inserts the populated document in the wrong array element.
In the example below, I have defined a
Class
model with an array ofstudents
where each element is a nested schemastudentSchema
. I have defined another modelGrade
which represents a student's grade in a class. The student schema has agrade
virtual representing the student's grade in the class (parent document).When populating the
grade
virtual, grades in the class are assigned to the incorrect student subdocument unless every student has a grade in the class.Steps to Reproduce
The following code shows the unexpected behavior of populating a virtual with a match() function on an embedded subdocument.
Output
Expected Behavior
The text was updated successfully, but these errors were encountered: