Skip to content
Advertisement

Firestore onSnapshot with “where” and “orderBy” not matching any documents

I am struggling to figure out why the following code produces the “doc.empty” console log. The screenshot shows what I see in Cloud Firestore’s data console. My abbreviated code is below. In my example, I have the following variables:

JavaScript

enter image description here

JavaScript

Why would this not match my data?

Advertisement

Answer

The problem is here:

JavaScript

The screenshot shows that your custnum field has a string value, yet you are explicitly passing a numeric value in the condition. Strings and numeric values are never the same in the database, so the condition doesn’t match the document you how.

To make the query work, make sure you pass the value as the same type that you’ve stored in the database.

Advertisement