I have read this code in the Firestore documentation:
const cityRef = db.collection('cities').doc('SF');
try {
const res = await db.runTransaction(async t => {
const doc = await t.get(cityRef);
const newPopulation = doc.data().population + 1;
if (newPopulation <= 1000000) {
await t.update(cityRef, { population: newPopulation });
return `Population increased to ${newPopulation}`;
} else {
throw 'Sorry! Population is too big.';
}
});
console.log('Transaction success', res);
} catch (e) {
console.log('Transaction failure:', e);
}
but I can't understand the purpose of awaiting the t.update() of the 8th line.
Wouldn't the code work the same way without awaiting for that 8th line?