我有一个基本数据库,本质上在用户下存储一系列产品 id。用户可以选择要添加到数组中的产品,因此使用“arrayUnion”是有意义的,因此我避免不断读取和重写数组,但是,我不断收到错误 *“属性“firestore”在类型“上不存在” Firebase命名空间'。”
我已按照以下位置找到的文档进行操作:https://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array 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)
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)