It’s a best practice in MarkLogic to lock a document, using xdmp.lockForUpdate()
, before you update it to avoid deadlocks. This got me thinking about how to better decouple concerns like locking, transactions, and other context from the actual implementation of transformation logic.
For example, let’s say I’ve implemented my update business logic in a pure function, (i.e. no side-effects) like,
function addOrUpdateKey(doc, key) {
return Object.assign(doc.toObject(), { [key]: key });
}