我有一个基本数据库,它本质上存储了用户下方的产品 ID 数组。用户可以选择要添加到数组的产品,因此使用 'arrayUnion' 是有意义的,因此我避免不断读取和重写数组,但是,我不断收到错误 *"Property 'firestore' does not exist on type ' Firebase 命名空间'。”
我遵循了以下位置的文档:https://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array但我担心我仍然在错误地使用它。
我更新数组的代码是:
addToPad(notepadName: string){
const updateRef = this.db.collection('users').doc(this.activeUserID).collection('notepads').doc(notepadName);
updateRef.update({
products: firebase.firestore.FieldValue.arrayUnion(this.productId)
});
}
最佳答案
首先需要导入firestore
:
import { firestore } from 'firebase/app';
然后你就可以使用
arrayUnion
:addToPad(notepadName: string){
const updateRef = this.db.collection('users').doc(this.activeUserID).collection('notepads').doc(notepadName);
updateRef.update({
products: firestore.FieldValue.arrayUnion(this.productId)
});
}
关于javascript - 如何将 arrayUnion 与 AngularFirestore 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59429562/