Firestore不查询用户集合中的文档

时间:2019-04-11 02:49:55

标签: javascript reactjs firebase google-cloud-firestore

![在此处输入图片描述] [1]

Firebase不会查询我的Firestore用户集合中的文档。

我一直在努力,我尝试使用多个不同的查询,我直接从文档中获取了该查询,但仍然无法正常工作。 “上面有开火”打印,但下面没有打印。

 export const fetchSwipeUsers = () => {
        return (dispatch) => {
              console.log('fetch in action fired');
              const userId = firebase.auth().currentUser.uid;
              const firestore = firebase.firestore();
              firestore.collection("users").get()
              .then(function(querySnapshot) {
                console.log('above is firiing');
                  querySnapshot.forEach(function(doc) {
                      console.log('this is firing');
                      console.log(doc.id, " => ", doc.data());
                  });
              })
                .catch(function(error) {
                    console.log("Error getting documents: ", error);
                });
        } //end
    }

It should query the two users that are present in my database but instead the console.log does not print at all.


  [1]: https://i.stack.imgur.com/15yJt.png

1 个答案:

答案 0 :(得分:0)

如果在之后添加catch,则如下:

    firestore.collection("users").get().then(function(querySnapshot) {
        console.log('this is the query snasphot', querySnapshot);
        querySnapshot.forEach(function(doc) {
            console.log(doc.id, " => ", doc.data());
        })
    }).catch(function(error) {
        console.error(error);
    });

然后,当您运行相同的代码时,请查看它是否在JavaScript控制台中显示错误。