You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Firebase Firestore runTransaction returns a Promise as you can see in the official docs
constcityRef=db.collection('cities').doc('SF');try{// here 👇constres=awaitdb.runTransaction(asynct=>{constdoc=awaitt.get(cityRef);constnewPopulation=doc.data().population+1;if(newPopulation<=1000000){awaitt.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 typesaurus types doesn't indicate that the result is a Promise and some transactions might not execute if you exit after the transaction (E.G. in firebase cloud functions, the function might die before the transaction has finished because we didn't await it)
The return type of write in typesaurus is WriteDocsToDocs<WriteResult, Props>
constresult=transaction(...).read(...).write((...)=>{// .... Transaction write ....return'DONE'})// Typescript -> result: string// Actual -> console.log("result",result)// result Promise {// <pending>,//...//},
The text was updated successfully, but these errors were encountered:
Firebase Firestore runTransaction returns a Promise as you can see in the official docs
But typesaurus types doesn't indicate that the result is a Promise and some transactions might not execute if you exit after the transaction (E.G. in firebase cloud functions, the function might die before the transaction has finished because we didn't await it)
The return type of write in typesaurus is
WriteDocsToDocs<WriteResult, Props>
The text was updated successfully, but these errors were encountered: