Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I query a Cloud Firestore collection with a where equals clause and an orderby?

The documentation states:

However, if you have a filter with a range comparison (<, <=, >, >=), your first ordering must be on the same field:

That implies that I can use the non-range comparison, "==", with the orderBy clause. But this fails:

myCollectionRef.where('age', '==', 2).orderBy('name');
like image 904
Paul Avatar asked Oct 19 '17 01:10

Paul


1 Answers

If you wanted to order a query with one or more equality filters, where the ordering is by a different field, you'll need to create a composite index.

You can read more about this in our "Managing Indexes" documentation section.

like image 96
Dan McGrath Avatar answered Oct 16 '22 11:10

Dan McGrath