如何在 Firestore 中处理承诺

How to handle promise in firestore

这是我的代码,用于检查 doc 是否存在于 collections

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

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

我正在使用 angularfire2 版本 ^5.0.0-rc.1 以及 angular ^4.2.4firebase ^4.5.0

请帮忙。

我做了一些更改后就可以使用了

这是我的代码

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)
      });

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