In order to be able to query on the target document more precisely, we need to update the Model.update method to also take an optional filter document. The document will be unpacked and the _id field will be forced to be the ObjectId of the current model. This will ensure consistent behavior.
This is needed when you need to conditionally perform an update on the target document and you want to use the DB as your mechanism of staving off race conditions. EG: you want to update a field on the model, but only if the field is currently null. If it is not null, then someone else beat you to the update and the operation should fail.
In order to be able to query on the target document more precisely, we need to update the
Model.update
method to also take an optional filter document. The document will be unpacked and the_id
field will be forced to be the ObjectId of the current model. This will ensure consistent behavior.This is needed when you need to conditionally perform an update on the target document and you want to use the DB as your mechanism of staving off race conditions. EG: you want to update a field on the model, but only if the field is currently null. If it is not null, then someone else beat you to the update and the operation should fail.