0
votes

I am trying to filter my docs in firebase firestore by checking if a doc 'users' array contains the user's email address. The 'chat' collection contains docs with ids: '[email protected]:[email protected]' and a doc contains messages and users stored in array.

I would like to list chats for the current user. The image shows one chat conversation in firestore

The problem is that every time I would like to use the where() clause I get to following error:

TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_1___default.a.firestore(...).collection(...).where(...).onSnapshot(...).catch is not a function

This is my code:

firebase.firestore().collection("chats").where("users", "array-contains", currentUser.email)
            .onSnapshot(async res => {
                setChats(res.docs)
            })
            .catch(function (error) {
                console.log("Error getting documents: ", error);
            });
1
Did you import firebase from 'firebase' ?Dilhan Bhagat

1 Answers

1
votes

After read the "onSnapshot" method reference I understood it does not return anything. The method signature has a void return. You may have to pass the callback you want to be called as parameter of the onSnapshot method.

Actually you have an exemple in the Firestore documentation at the Handle listen errors section.

Bellow the snippet of code from the documentation:

db.collection("cities")
  .onSnapshot(function(snapshot) {
    // Handle changes
  }, function(error) {
    // Handle errors
  });