我只是想在我的 Cloud-Firestore 中增加
一个值
,但我无法完成它,也找不到任何文档中的解决方案..
这是我尝试过的:
let batch = db.batch()
// Set username and uid for user
let userRef = Firestore.firestore().collection("users").document(userID)
batch.updateData(["population": FieldValue.increment(1)], forDocument: userRef)
但这给了我这个错误
:
Ambiguous use of 'increment'
完成此任务的正确方法是什么?这实际上可以通过batch
实现吗?
更新:我想使用batch
的原因是在函数内部我还需要更新一些其他字段。
最佳答案
我想你可以试试这个:
let batch = db.batch()
let userRef = Firestore.firestore().collection("users").document(userID);
batch.update(userRef, "population", firebase.firestore.FieldValue.increment(1));
Firestore 文档: https://firebase.google.com/docs/firestore/manage-data/transactions
关于ios - 使用批处理在 Firestore 内增加值 - "Ambiguous use of ' 增量'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60874977/