【发布时间】:2018-12-11 20:09:32
【问题描述】:
有没有办法更新两个文档,每个文档都在不同的 收集,一个请求?
我知道您可以使用 FIRWriteBatch 批量写入 - 这似乎仅限于 same 任何文档更新的集合。尝试为两个不同集合中的文档附加更新时:
// Just for example
FIRWriteBatch *batch = FIRWriteBatch.new;
[batch updateData:@{@"posts" : @1} forDocument:[self.firebase.usersCollection documentWithPath:@"some_user_id"]];
[batch setData:@{@"test" : @"cool"} forDocument:[self.firebase.postsCollection documentWithPath:@"some_post_id"]];
[batch commitWithCompletion:^(NSError * _Nullable error) {
NSLog(@"error: %@", error.localizedDescription);
}];
它永远不会执行 - 应用程序崩溃,我明白了:
Terminating app due to uncaught exception 'FIRInvalidArgumentException', reason:
'Provided document reference is from a different Firestore instance.'
显然该批次不喜欢在多个集合中进行更新。
- 有谁知道如何更新两个文档,每个文档位于不同的集合中,而一个失败另一个成功?
我想避免,例如,为 usersCollection 中的文档成功设置 posts = 1,而 未能 在 postsCollection 中编写新文档强>。
我知道一个人写而另一个人失败是不太可能的,但在这种情况确实发生的情况下,我显然不想要不一致的数据。
注意:
对于任何关心的人 - 我不知道它是否会失败,但到目前为止,我正在运行事务没有在更新数据之前读取文档。 .. ????♂️ 为-1 API 调用干杯!
【问题讨论】:
标签: objective-c firebase google-cloud-firestore