Josh Pittman
Josh Pittman

Reputation: 7344

Firestore .orderBy() to also return documents without the field being queried

I updated a collection of documents with a new field that corresponds to a new feature. A rating out of 5. Previously I had a list all the documents in the order they were created in. Now I want to show all the documents in order of their rating. The problem with using .orderBy is that it only returns the newer documents with the rating field. Is there a way to return all documents, in order of rating, but to also include document that don't have ratings at the bottom?

Upvotes: 2

Views: 66

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600141

All Firestore queries are optimized to return documents in a single range. Your requirement essentially become an OR condition, where it'd need to return documents from two ranges. This currently isn't possible in Firestore queries.

Upvotes: 2

Related Questions