批量更新作为集合操作
Batch update works as set operation
我需要使用 Firebase 的实时数据库进行批量更新。我是这样做的:
这工作正常。但我只需要为第二次操作更新。此时它作为 set
操作。有什么线索吗?
const updates = {}; //batch operation
// this is working fine and I need it as set operation
updates[`groups/${this.groupId}/leads/${lead.id.toString()}`] = {
name: lead.name,
address: lead.address,
};
// But problem is here. I need to write it as update operation
updates[`groups/${this.groupId}/addresses/${lead.id.toString()}`] = {
address: lead.address,
};
return this.angularFireDatabase.object('/').update(updates);
多路径更新在您传入的地图中的每个单独键上充当 set
。由于您传入 groups/${this.groupId}/addresses/${lead.id.toString()}
作为键,它 设置 您在该路径上指定的值。
如果您只想更新该路径下的 address
属性,请在路径中包含 address
键,而不是在值中:
updates[`groups/${this.groupId}/addresses/${lead.id.toString()}/address`] = lead.address;
我需要使用 Firebase 的实时数据库进行批量更新。我是这样做的:
这工作正常。但我只需要为第二次操作更新。此时它作为 set
操作。有什么线索吗?
const updates = {}; //batch operation
// this is working fine and I need it as set operation
updates[`groups/${this.groupId}/leads/${lead.id.toString()}`] = {
name: lead.name,
address: lead.address,
};
// But problem is here. I need to write it as update operation
updates[`groups/${this.groupId}/addresses/${lead.id.toString()}`] = {
address: lead.address,
};
return this.angularFireDatabase.object('/').update(updates);
多路径更新在您传入的地图中的每个单独键上充当 set
。由于您传入 groups/${this.groupId}/addresses/${lead.id.toString()}
作为键,它 设置 您在该路径上指定的值。
如果您只想更新该路径下的 address
属性,请在路径中包含 address
键,而不是在值中:
updates[`groups/${this.groupId}/addresses/${lead.id.toString()}/address`] = lead.address;