Is there a way to retrieve the updated value of a document field updated using firestore.FieldValue.increment
without asking for the document?
var countersRef = db.collection('system').doc('counters');
await countersRef.update({
nextOrderCode: firebase.firestore.FieldValue.increment(1)
});
// Get the updated nextOrderCode without asking for the document data?
This is not cost related, but for reliability. For example if I want to create a code that increases for each order, there is no guaranty that if >= 2
orders happen at the same time, will have different codes if I read the incremental value right after the doc update resolves, because if >= 2
writes happen before the first read, then at least 2 docs will have the same code even if the nextOrderCode
will have proper advance increment.