0

I am creating an app where people can read messages and in firestore, once they have read a message it adds the user's uid (who read it) to the specific doc, like so:

hasread
    userId -> uid

What I am trying to do, is count the amount of docs that do not have the user's uid and return that number.

const usrId = firebase.auth().currentUser.uid;
const countNewAnnounce = this.announce
        .where('hasread.userId', '!=', usrId)
        .get()
        .then(snapshot => {
            console.log('size', snapshot.size);
        })
        .catch(err => {
            console.log('Error getting documents', err);
        });

The snapshot.size will always return the total amount of docs, so somehow the where is not working correctly or I am not using it correctly (probably the last).

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
udarts
  • 745
  • 1
  • 8
  • 23
  • 1
    Firestore does not have a `!=` operator. The common workaround is to do two separate queries one for `<` and one for `>`. See https://stackoverflow.com/questions/47251919/firestore-how-to-perform-a-query-with-inequality-not-equals – Frank van Puffelen Jul 03 '18 at 13:11
  • 2
    Possible duplicate of [Firestore: how to perform a query with inequality / not equals](https://stackoverflow.com/questions/47251919/firestore-how-to-perform-a-query-with-inequality-not-equals) – Frank van Puffelen Jul 03 '18 at 13:11

0 Answers0