如何在firestore中处理承诺

Har*_*esh 1 javascript promise firebase angularfire2 google-cloud-firestore

这是我的代码来检查a中doc是否存在collections

this.shopCollection = this.afs.collection<Shop>('shops', ref => {
  return ref.where('fulladdress', '==', myString)
});
Run Code Online (Sandbox Code Playgroud)

我不知道为什么我不能用.then(),并.catch()用此方法.当我传递一个字符串进行查询,如果没有找到结果我怎么知道?

我使用的angularfire2版本^5.0.0-rc.1angular ^4.2.4firebase ^4.5.0.

请帮忙.

Har*_*esh 5

我得到了一些改变

这是我的代码

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)
      });
Run Code Online (Sandbox Code Playgroud)

我不确定这是正确的方法,对我来说很好.