0

處理諾言這裏是我的代碼來檢查doc有在collections如何在公司的FireStore

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

我不知道爲什麼我不能用.then().catch()用這種方法。當我傳遞一個字符串來查詢,如果沒有結果發現我怎麼知道?

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

請幫忙。

+0

您是否在談論使用這種方法? https://firebase.google.com/docs/reference/js/firebase.firestore.Firestore#collection –

+0

@DougStevenson是的,因爲我使用'angularfire2',他們稱之爲'AngularFirestoreCollection'。它看起來都是一樣的。 – Hareesh

+0

返回的AngularFirestoreCollection不是承諾。看看這些文檔,找出你可以用它做什麼,你有幾個選擇:https://github.com/angular/angularfire2/blob/master/docs/firestore/collections.md –

回答

2

我得到了它的一些變化

在這裏工作是我的代碼

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

我不知道這是正確的方式,對我來說工作正常。