如何在firestore中处理promise [英] How to handle promise in firestore

查看:24
本文介绍了如何在firestore中处理promise的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,用于检查 collections

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

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

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?

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

I am using angularfire2 version ^5.0.0-rc.1 with angular ^4.2.4 and firebase ^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)
      });

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

i am not sure this is the right way, works fine for me.

这篇关于如何在firestore中处理promise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆