ios - 使用批处理在 Firestore 内增加值 - "Ambiguous use of ' 增量'"

标签 ios swift firebase google-cloud-firestore

我只是想在我的 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/

相关文章:

c# - Xamarin IOS 蓝牙 LE 广告

ios - 尝试实现 Facebook 即时文章页面,但我无法获取 ImageView 高度以进行动画处理

iphone - UIView 动画,变换 layer.shadowPath

javascript - MediaDevices.getUserMedia() 提示用户获得许可,然后在全屏而不是在浏览器中启动相机应用程序

firebase-messaging - 致命的 : failed to find callback

ios - 通过另一个 ObObject 传递 ObservableObject 模型?

ios - iPhone 和 iPad 上的边到边对象

ios - 更改 UITableViewCell 中标签的字体属性

android - Firebase 通知推送通知不工作

android - firebase 应用索引和应用链接之间的区别