let db = Firestore.firestore()
let batch = db.batch()
let timestamp = FieldValue.serverTimestamp()
batch.updateData([
"private.index.\(someId)": ["count": 0, "timestamp": timestamp]
], forDocument: db.collection("someCollection").document(uId))
batch.deleteDocument(db.collection("anotherCollection").document("\(uId)-\(someId)"))
batch.commit { (error) in
if let error = error {
print(error)
}
}
如果快照侦听器忽略返回
hasPendingWrites
,数据很好,因为它来自服务器(这是正确的)。但是,如果快照侦听器允许延迟补偿数据,我会得到:
["count": 0, "t": <null>]]
来自服务器(和事务)的数据如下所示:
["count": 0, "t": <FIRTimestamp: seconds=1586033607 nanoseconds=198000000>]]
时间戳不应该为零。
同样奇怪的是,如果我在一个事务中执行相同的任务,就不会有问题,即使有延迟补偿数据(这是正确的)。
db.runTransaction({ (trans, errorPointer) -> Any? in
trans.updateData([
"private.index.\(someId)": ["count": 0, "timestamp": timestamp]
], forDocument: db.collection("someCollection").document(uId))
trans.deleteDocument(db.collection("anotherCollection").document("\(uId)-\(someId)"))
return nil
}) { (_, error) in
if let error = error {
print(error)
}
}
批处理写入有时会不会给出一致的延迟补偿结果,因为它们不像事务那样工作?