【发布时间】:2020-08-16 16:00:53
【问题描述】:
我正在使用snapshotChanges() 获取数据。我想向它添加where 条件并从collection 中仅获取1 个文档 的数据。
下面是我的代码:
this.firestore.collection('notifications' , ref => ref
.where(document id , "==" , "1") // giving error
)
.snapshotChanges()
.subscribe(response => {
if(!response.length){
console.log("no data available");
return false;
}
this.notifyarr = [];
for(let item of response){
this.notifyarr.push(item.payload.doc.data());
console.log(this.notifyarr);
this.notification_length = this.notifyarr.length;
console.log(this.notification_length);
}
})
这行代码报错.where(document , "==" , "1") // giving error
我们如何使用.snapshotChanges() 引用文档?
【问题讨论】:
-
你遇到了什么错误..!?
-
document不是正确的词,我想知道如何引用doc,写什么来代替document?? -
您引用文档的方式正确,您的引用没有问题。你得到什么错误..?!
-
nope - 错误 - 'Document' 类型的参数不可分配给'string | 类型的参数场路径”。类型“文档”不可分配给类型“字符串”。
-
尝试使用 ` .where(ref.id , "==" , "1") ` 但它显示 `没有可用数据
标签: firebase google-cloud-firestore angularfire