简体   繁体   中英

Cloud Functions and Firestore: Using Promise.all() to track multiple documetn modifications

I use a callable Cloud function for creating a new user. For this user, multiple documents in Cloud Firestore are created.

I do not want to store only parts of the data, if one promise (document creation fails), but completely undo the registration, so I use Promise.all(documentCreationPromisses)

So my question is if it is still possible that some documents are created and others are not, although I use Promise.all() ?

Promise.all() returns a promise that tells you if all of the other promises succeeded, or if any one of them failed. It can certainly resolve with a partial set of successes, and there was a failure, you would have to check each individual promise to find out which ones succeeded or failed.

If you are modifying a bunch of documents in Firestore, and you require that all of the modifications either fully succeed, otherwise nothing happens (a full rollback), then you should use a batch write or transaction . With a batch writes and transactions, everything must succeed, or the entire batch fails. The single returned promise from that batch will tell you what happened.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM