-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Model.applyVirtuals(): apply schema virtuals to a POJO, similar to Model.applyDefaults() #14818
Comments
"Virtuals are properties on Mongoose documents. If you use the lean option, that means your queries return POJOs rather than full Mongoose documents. That means no virtuals if you use lean()." Aggregate returns POJO, just like lean. Since virtuals are tied to mongoose documents, they won't work with aggregation results. |
I understand totally. |
I think adding a |
Yes, that sounds great, @vkarpov15 |
feat(model): add `Model.applyVirtuals()` to apply virtuals to a POJO
Prerequisites
🚀 Feature Proposal
Supporting virtual fields in aggregate will be good feature.
I know aggregate is server-side feature and virtual fields is client-side feature and aggregation results can change shape of document.
However, some aggregate results just extends document data and it is possible to add virtual fields to aggregate results, just I mentioned in motivation.
I think we can add
hasVirtualFields
to aggregate options which default is false and add virtual fields to aggregate results.Motivation
I am using aggregate function for pagination.
Since aggregate doesn't support virtual fields, I need to hydrate each aggregation result and add virtual fields to each aggregation result manually.
It will be good to do in mongoose itself.
Example
So, we can add virtual fields like
fullName
to aggregate results.The text was updated successfully, but these errors were encountered: