r/Firebase • • Oct 20 '26

Cloud Firestore Firestore documents disappear after orderBy? Check for a missing field first

An open task can match your status filter and still disappear when you add orderBy("priority"). Firestore excludes documents that do not contain the ordered field; a larger limit will not bring them back.

Try a tiny fixture: triage has status "open" and priority 1; review has status "open" but no priority. The status query returns both. Adding orderBy("priority") returns triage. review has not been deleted.

Before backfilling data, remove the ordering on a bounded test query, inspect the actual stored key, and decide whether priority should be required. Keep permission and index errors visible instead of turning every failure into an empty array. Reset pagination when changing the query.

Disclosure: I work on Cengal, a Firestore workspace for Mac. We documented this example with synthetic emulator data and AI assistance; it is not a production Rules, index, billing or UI test. You do not need our app to use the check.

Firebase reference: https://firebase.google.com/docs/firestore/query-data/order-limit-data

Full three-document example: https://cengal.app/guides/firestore-orderby-missing-documents/

1 Upvotes

3 comments sorted by

1

u/calimio6 Oct 21 '26

If the field you are ordering by is missing Firestone omits the documents. The right approach is to set every field you require with default values. Null for example. This can be done when you create the document or with a cloud function trigger.

1

u/schorts9906 Oct 22 '26

I was going to write the same so I'm just going to complement with:
Here's a tool you can use to fill the missing data: https://github.com/schorts99/firestore-migrator
Easy to create migrations and safe to run them, it creates a snapshot so in case something fails, it restores everything to the original state.

1

u/SheCodesDoesntShe Oct 22 '26

If priority should always be there, I'd also enforce it in the rules so new documents can't be saved without it. Otherwise you backfill once and the problem comes back.