我正在使用Cloud Firestore(不是实时数据库)。我有一个包含用户信用卡阵列(卡对象)的用户详细信息文档。卡对象的结构如下:
{
address: "123"
number: "456643634634634"
postcode: "hshshs"
}
文档定义如下:
userDocument : AngularFirestoreDocument<User>;
this.userDocument = this.afs.collection('users').doc(`${this.userId}`);
当用户添加新卡时,我调用以下功能:
addCard(card: Card){
this.userDocument.update({
cards : firebase.firestore.FieldValue.arrayUnion(card)
});
}
但是,在保存文档之前,我遇到了错误:
[ts]
Type 'FieldValue' is not assignable to type 'Card[]'.
Property 'length' is missing in type 'FieldValue'. [2322]
user.model.ts(15, 5): The expected type comes from property 'cards' which is declared here on type 'Partial<User>'
不确定如何使用arrayUnion
将元素正确添加到Cloud Firestore中的阵列。有人可以帮忙吗?