Skip to content

Model.applyVirtuals(): apply schema virtuals to a POJO, similar to Model.applyDefaults() #14818

Closed
@Vladyslav531

Description

@Vladyslav531

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 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

UserModel.aggregate([
  // add pipelines
], {
  hasVirtualFields: true
});

So, we can add virtual fields like fullName to aggregate results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new featurenew featureThis change adds new functionality, like a new method or class

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions