-
-
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
*Feature Request* Use fields in Populate Virtuals #5704
Comments
I like this idea, should be doable, will investigate for next minor release. |
@vkarpov15 We just updated our mongoose version and I tried to get this to work. Could you please add the syntax to the documentation or provide a basic example? I have this but it throws an error Baiscally what I try to accomplish here is to set the virtual dynamically based on a field of the source document (RefundSchema)
EDIT: Is it by any chance that the foreignField does not support documents _id field? |
Okay, I figured out the syntax but there seems to be a bug.... I have the following virtual with dynamic localField and foreignField
Now I have two queries that produce inconsistent results:
Actual Behaviour Expected Behaviour |
Thanks for reporting @florianbepunkt , will investigate |
Thanks for your patience @florianbepunkt , we really kicked this issue very far down the road. The issue should be fixed in 5.2.18. |
It would be useful for some use cases to set the references in populated virtuals based on existing fields in the doc, if this is possible. See the following example. If the field
internalOrderId
in the Refund document is no null, it usessourceOrderId
as localField, if it is null, it uses_id
.You can do something similar already when you populate fields using a dynamic ref, but since I can't use the _id field as reference this is not an option. As far as I know, you can't do the same when you use populate virtuals.
The text was updated successfully, but these errors were encountered: