Firestore:如何更新作为文档引用的文档字段?

时间:2019-03-23 00:06:19

标签: javascript angular firebase google-cloud-firestore angularfire2

我将Firestore与AngularFire 2一起使用,并且我的一个字段引用了另一个文档。

我可以在我的角度应用程序中使用此字段,但是:如何更新此字段?

我正在尝试创建一个指向正确引用的新AngularFirestoreDocument,但我得到了:

  

DocumentReference.update()用无效数据调用。不支持的字段值:自定义AngularFirestoreDocument对象

public updateConfig(newConfig: ConfigId) {
    const preset: AngularFirestoreDocument<Config> = this.db.doc<Config>('/reference/path');
    this.businessDoc.update({'config': preset})
}

谢谢!

1 个答案:

答案 0 :(得分:1)

这很简单,但是深入了火力场。只需将.ref添加到您的AngularFirestoreDocument

public updateConfig(newConfig: ConfigId) {
    const preset: AngularFirestoreDocument<Config> = this.db.doc<Config>('/presets/' + newConfig.id);
    this.businessDoc.update({'config': preset.ref})
}
相关问题