0

I try to mix where and orderBy but this code doesn't work:

Stream<QuerySnapshot> getTop10Songs() async* {
    yield* fireStore.collection('programs').where('title', isEqualTo: 'Lama').orderBy('subtitle').limit(2).snapshots();
  }

But if I remove orderBy('title').. It works fine. How should I do? Thank you

Phuoc
  • 966
  • 3
  • 7
  • 20
  • Thank you for all your advices. I solved this issue by: https://stackoverflow.com/questions/56614131/firestore-orderby-and-where-conflict – Phuoc Mar 06 '21 at 00:47

1 Answers1

0

There are two restrictions on using orderBy():

  • An orderBy() clause also filters for existence of the given fields. The result set will not include documents that do not contain the given fields.
  • If you include a filter with a range comparison (<, <=, >, >=), your first ordering must be on the same field

Second seems like not your case, so the only bet is that your queried documents have no field subtitle. Have a check if they exist or if there is a typo somewhere.

Simon Sot
  • 2,748
  • 2
  • 10
  • 23