Firestore transactions hold a pessimistic lock on the documents read in it. Does this lock apply even when the document doesn't exist?
Following the example from the nodejs docs:
firestore.runTransaction(transaction => {
let documentRef = firestore.doc('col/doc');
return transaction.get(documentRef).then(doc => {
if (doc.exists) {
transaction.update(documentRef, { count: doc.get('count') + 1 });
} else {
transaction.create(documentRef, { count: 1 });
}
});
});
If two transactions read and modify the same non-existing doc col/doc will one of them fail and attempt a rerun?
Also create method has it's own failure behavior - "The operation will fail the transaction if a document exists at the specified location.". Is the usage of create, compared to set+merge, safe in this context?