这应该是很容易的任务。您可以使用更新功能,并传递字段名称和值以进行更新。
例如:
this.db.doc(`options/${id}`).update({rating:$rating}); //<-- $rating is dynamic
Run Code Online (Sandbox Code Playgroud)
好的,您必须执行以下步骤:
它看起来像这样:
updateDoc(_id: string, _value: string) {
let doc = this.afs.collection('options', ref => ref.where('id', '==', _id));
doc.snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
}))).subscribe((_doc: any) => {
let id = _doc[0].payload.doc.id; //first result of query [0]
this.afs.doc(`options/${id}`).update({rating: _value});
})
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4083 次 |
| 最近记录: |