Calculated field base on another field. How to update?


Hello this code updates a record in a collection

Task.update(id, {‘status’:‘doing’});

however i need to calculate a field based on another field of the same record.
how di i do it ?
do i have to find the record first and then update it ?


try these


Yes you do. But if you can infer the second field based on the first one, are you sure you actually need to store the second field? Or can’t you store the first and second fields at the same time?


This is the case
I have a record with creation date and another field named “text” that stores the elapsed time from the creation to now.

I then have a timer that each minute updates this elapsed time but needs to get first the creation time

I solved it using this code as suggested by @corvid

list.before.update(function (userId, doc, fieldNames, modifier, options) {
modifier.$set = modifier.$set || {};


Maybe there is a better way but for now i´m good.