A document has the following schema when an order is created:
{order:1,startTime:1402442830110}
When an order is finished, a db.collection.findAndModify()
operation is processed to set the endTime resulting in a document like so:
{order:1,startTime:1402442830000,endTime:1402442930000}
In that same process, I need to set the order duration
, calculated by subtracting both times: doc.endTime-doc.startTime
.
Is there an operator or procedure that helps do this in a single operation? Or do I have to perform two FindAndModify operations, one to set the new data returning the new document and another to set the duration
field?