Firestore的FieldValue.increment(someValue)
与其他字段一起工作,但不能与map一起使用。
我正在尝试增加地图中属性的值。我有一个名为 user 的文档。它有一个地图points:{id:123, total:100}
。我想更新地图points
中total
的值。
firestore.collection('users').doc('user').update({
"name": "atul",
"points": { "total": firestore.FieldValue.increment(50) }
})
其值变为 100,而不是将total
值增加到 150。
您需要调用要递增的字段的完整路径,而不是将其埋在对象中。 字段的完整路径涉及使用 .
作为每个字段名称之间的分隔符:
firestore.doc(...).update({
"points.total": firestore.FieldValue.increment(50)
})