Geetanshu Gulati
Geetanshu Gulati

Reputation: 772

Issue in Order by in firestore

How to return all documents having specific field as null when we apply orderBy on that specific field in collection in firestore

For example I have a 2 document one having "createdDate" field and other not. I make a query to orderMy Date acc to "createdDate field". firestore.collection("collection").orderBy("createdDate").get()

The result I am getting has only 1 record, that record contains createdDate and It skipped that document that doesn't have "createdDate" field

But I want all the documents

Upvotes: 2

Views: 1096

Answers (1)

Sam Stern
Sam Stern

Reputation: 25134

[Firebaser here] this is an intrinsic limitation of Firestore, when you orderBy a field you filter out all documents that do not have that field.

There is no way to query documents which do not have a certain field in Firestore.

That said there is a difference between no value and null value. If you store null in the field by default, you can query for that.

Upvotes: 3

Related Questions