如何处理firestore中的承诺 [英] How to handle promise in firestore
问题描述
这里是我的代码来检查 doc
是否存在于集合中
this.shopCollection = this.afs.collection< Shop>('shops',ref => {
return ref.where('fulladdress' ,'==',myString)
});
我不知道为什么我不能使用 .then()
和 .catch()
。当我传递一个字符串来查询,如果没有结果发现我怎么知道?
我使用 angularfire2
版本 ^ 5.0.0-rc.1
with angular ^ 4.2.4
和 firebase ^ 4.5。 0
。
请帮助。
我得到了一些改变工作
这是我的代码
$ $ $ $ $ $ ('fuldsdress','==',myString)
.get()
.then(res => {
if(res.docs.length == 0){
//找不到文件
} else {
//你有一些文件
res.forEach (shop => {
console.log(shop.id);
console.log(shop.data());
})
}
} ).catch(err => {
console.log('something went wrong'+ err)
});
我不确定这是正确的方法,对我来说很好。
here is my code to check a doc
is there in the collections
this.shopCollection = this.afs.collection<Shop>('shops', ref => {
return ref.where('fulladdress', '==', myString)
});
i don't know why i can't use .then()
and .catch()
with this method. When i pass a string to query and if no result found how i know?
I am using angularfire2
version ^5.0.0-rc.1
with angular ^4.2.4
and firebase ^4.5.0
.
Please help.
I got it working with some changes
Here is my code
this.afs.collection<Shop>('shops').ref.where('fulladdress', '==', myString)
.get()
.then(res => {
if(res.docs.length == 0){
//no documents found
}else{
//you got some documents
res.forEach(shop => {
console.log(shop.id);
console.log(shop.data());
})
}
}).catch(err => {
console.log('something went wrong '+ err)
});
i am not sure this is the right way, works fine for me.
这篇关于如何处理firestore中的承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!