【发布时间】:2020-10-28 21:25:36
【问题描述】:
我了解在嵌套对象中使用Firestore FieldValue increment 函数我需要在update 方法中提及完整路径。我的 Ionic 5 项目的 main 方法采用对象字段的名称。以下是我尝试使用它的方式
updateCounter(attr: string){
Way1:
let obj = {};
obj[attr] = firebase.firestore.FieldValue.increment(1); //This is working
obj.count[attr] = firebase.firestore.FieldValue.increment(1); //This is not working. Value is always 1
this.afs.doc('path').update(obj);
Way2:
this.afs.doc('path').update({
'count.${attr}': firebase.firestore.FieldValue.increment(1); //Creating a field called '${attr}' and not replacing the value;
});
Way3:
this.afs.doc('path').update({
`count.${attr}`: firebase.firestore.FieldValue.increment(1); //Error as '``' value not accepted in the function
});
}
【问题讨论】:
标签: javascript ionic-framework google-cloud-firestore