-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
Virtuals are just functions and not real object which can hold information.
My request:
As other ORM allow (this isn't implying mongoose should always "do what others do"), i am missing the possibility to store additional data on a document on runtime, which isn't saved to the database.
As @vkarpov15 already wrote you can just save data to some attribute called _myAttr and create a virtual getter/setter to access this.
This "works" but in my opinion it would be much more understandable and easier to add a new Attribute-Type "Virtual", which is a property that exists on the document but is never saved to the database.
I could think of something like
tempAttr: { type: Virtual, of: String, required: false }This way there could be any data stored on the document which can be accessed/changed from multiple sources (parent-code, hooks, validation).
Use-case would be, for example, if i want to have a virtual attribute which contains some calculated value that is processing-intensive (and needs to query the database).
It's not performant to always process and query the needed data everytime it's needed during runtime.
What do you think of this?
If you want to have a look how this could look like, "sequelize" uses this new datatype and i think "TypeORM" does it too.