0

this is my code

  late final Stream<QuerySnapshot> products = productsRef
  .where('submitters', arrayContains: uid)
  .where('postState', isNotEqualTo: 'completed')
  .orderBy('createdAt', descending: true)
  .snapshots();

here's the error log enter image description here

without orderBy it works fine

SILENMUS
  • 709
  • 1
  • 10
  • 25
  • 1
    Looks like it means what it says. Your orderBy has to refer to a field selected by a where clause. It isn't. – Randal Schwartz Sep 21 '22 at 02:35
  • In the future please don't paste images of textual content, as it makes it hard to search for it. Instead post the actual text, and use the formatting tools of Stack Overflow to mark it up. Also see: [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) – Frank van Puffelen Sep 21 '22 at 03:33
  • you're right, I'll do it next time – SILENMUS Sep 21 '22 at 04:25

1 Answers1

3

Compound queries must orderBy on the same field as you are filtering by. In this case it would be postState for you. You are limited to order by that field since you are using it for != comparison.

It is not explicitly mentioned in the documentation, it is hinted in this note on limitations: https://firebase.google.com/docs/firestore/query-data/queries#limitations

Since you are not using a limit() on your query, you can still accomplish the same result by piping your result set and implement an array-sort locally on the createdAt field.

Dennis Alund
  • 2,916
  • 1
  • 13
  • 34
  • 1
    no worry , I'll do it if there is no more good answer, now I'm just waiting another answers. don't wait for me though can't promise when – SILENMUS Sep 21 '22 at 02:58