I am not aware of any “formula” type field in MongoDB. May be mongoose can do it for you.
In plain mongo, you may
- update the field like I shared
- compute the field with a projection every time you find or aggregate
- create a view with the same aggregation as #2 above
#1 is the fastest but takes more space, the computed value can be indexed, it has a high risk of becoming out of sync if documents are manipulated without your API