1

I have a query that looks for a gameCreatedAt that is equal to null. However, even though there are no null values in the collection..it still returns data o.O

Here is what the query looks like:

const query = firestore().collection('matches')
  query.where('gameStartedAt', '==', null)
  query.where(`lobby.${uid}`, '>', 0)
  query.orderBy('createdAt', 'desc')
  query.limit(1)

Here is what the data looks like: enter image description here

Not sure why the query.where('gameStartedAt', '==', null) criteria seems to get dropped silently? Was hoping someone could explain why the behavior is this way? It seemed to work in other programming languages with a NSNULL() like in this stackoverflow but in JavaScript null seems to just get ignored.

afreeland
  • 3,889
  • 3
  • 31
  • 42

1 Answers1

1

The problem is that query method is returning new query object, not changing the object on which it was called (reference).

You can do something like that (just remove query) in every line:

const query = firestore().collection('matches')
  .where('gameStartedAt', '==', null)
  .where(`lobby.${uid}`, '>', 0)
  .orderBy('createdAt', 'desc')
  .limit(1)

This should work fine.

vitooh
  • 4,132
  • 1
  • 5
  • 16