简体   繁体   English

Cloud Functions 和 Firestore:使用 Promise.all() 跟踪多个文档修改

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

I use a callable Cloud function for creating a new user.我使用可调用的 Cloud 函数来创建新用户。 For this user, multiple documents in Cloud Firestore are created.对于此用户,会在 Cloud Firestore 中创建多个文档。

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)我不想只存储部分数据,如果一个承诺(文档创建失败),而是完全撤消注册,所以我使用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() ,但是否仍有可能创建某些文档而其他文档则没有?

Promise.all() returns a promise that tells you if all of the other promises succeeded, or if any one of them failed. Promise.all()返回一个承诺,告诉您所有其他承诺是否成功,或者其中任何一个都失败了。 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 .如果您正在 Firestore 中修改一堆文档,并且您要求所有修改要么完全成功,否则什么都不会发生(完全回滚),那么您应该使用批量写入或事务 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.该批次返回的单个承诺将告诉您发生了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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