strip option to Model.hydrate(...)
#15940
AbdelrahmanHafez
started this conversation in
Ideas
Replies: 1 comment
-
|
Check out PR #15944 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In #15638 we created a
virtuals: booleanoption toModel.hydrate(...)that allows people to hydrate virtual paths to aggregated results, the virtual path mentioned in #15627 doesn't have a particular type, it's the equivalent of "Mixed" which I assume is just added for this purpose. IMO the "virtual" path here is not special at all, it's just added to enable adding an arbitrary field to be hydrated.I wonder if we should have a
stripoption that defaults totrue, this option would dictate how Mongoose should handle fields that are not explicitly defined in the schema. I can now think of many cases where I would've liked to cast aggregation results without stripping the additional fields by usingModel.hydrate(rawResult, null, { strip: false });.Thinking out loud here: If we agree to implement that, we can even take it further and make
Model.aggregate(...)accept acast: boolean, strip: boolean, that would enable people to docast: true, strip: false, which would be very useful for casting aggregation pipelines that mostly add/remove fields without fundamentally changing the shape of the document, while keeping the non-defined fields as is. I'd even think it's worth discussing making this the default behavior of aggregation pipelines, I can see a couple of arguments for both with and against this.I'd be happy to implement these features if we agree to add them.
What do you think? @vkarpov15 @hasezoey
Beta Was this translation helpful? Give feedback.
All reactions