Firestore的FieldValue.increment(someValue)可以与其他字段一起正常工作,但不能与映射一起工作。
我正在尝试增加地图中某个属性的值。我有一个名为user的文档。它有一个地图points:{id:123, total:100}。我想在地图points中更新total的值。
firestore.collection('users').doc('user').update({
"name": "atul",
"points": { "total": firestore.FieldValue.increment(50) }
})total的值将变为100,而不是递增到150。
发布于 2019-06-03 21:02:20
您需要调用字段的完整路径来递增,而不是将其隐藏在对象中。字段的完整路径包括使用.作为每个字段名称之间的分隔符:
firestore.doc(...).update({
"points.total": firestore.FieldValue.increment(50)
})https://stackoverflow.com/questions/56427582
复制相似问题