-
-
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
Populate Virtuals fails when localField is inside array (with reproduction code and data) #14315
Comments
Something interesting that I also noticed is that... while sniffing the activity in the db using these 2 mongo commands:
I noticed that mongoose DID the query to gather the data of the 2 'units' required to populate the second .populate()... (following report is in reverse time order)
which means that the feature is "trying" to work... gathering the data but then not being able to plug it in the model |
I think the issue is due to the
to the following:
shows the correct output:
I'll look into why the |
wow... you are right @vkarpov15. instruction:
outputs:
MISSING THE 'unit' attribute... BUT.... : instruction:
outputs:
which proves your point... the data is there in the model.. it's just the serialization part that is missing to expose it amazing so... this part:
seems to be the one that works in one case... and fails to work in the other case |
fix: include virtuals in document array `toString()` output if `toObject.virtuals` set
Prerequisites
Mongoose version
8.1.1
Node.js version
20.5.0
MongoDB server version
7.0.4
Typescript version (if applicable)
na
Description
While trying to use "Populate Virtuals" I noticed that the feature that makes it work for sub-elements and, I imagined, also sub-arrays... fails to work in this latter case.
I created an isolated piece of data+code to make sure I was not getting confused... so I can share that as a reproduction snippet.
I also checked this same code with previous versions of mongoose just in case it could be a recent bug... but I confirmed it fails to delived my expected results on all these versions:
8.1.1 - 7.6.8 - 6.12.2
And the part that works for me also fails while going down to
5.13.22
which means that the feature that I'm trying to make work started to appear in 6.x version
Steps to Reproduce
Expected Behavior
In the code sample I print out 2 cases; one working and one not working.
This is the obtained-vs-expected results of each case:
The text was updated successfully, but these errors were encountered: