0

I am using the following query:

Query postsQuery = FirebaseFirestore.instance.collection('posts')
  .where('postType', isNotEqualTo: 'Discussion') //post types - Simple, featured, discussion
  .orderBy('createdAt', descending: true)
  .where('group', isEqualTo: groupName) //india, usa, pakistan
  .limit(perPage);

The query runs if i remove this :

.where('postType', isNotEqualTo: 'Discussion')

Anyone knows what i am doing wring here?

3
  • Have you declared the index? Commented Oct 6, 2021 at 20:04
  • what index are you talking about ? Commented Oct 6, 2021 at 20:05
  • Also, if its' a compound query, then the vscode logs show the link in order to build index for the query but the logs aren't showing anything. Commented Oct 6, 2021 at 20:07

1 Answer 1

2

It seems that you haven't declare the Firestore index corresponding to your query.

As explained in the doc:

Cloud Firestore ensures query performance by requiring an index for every query. The indexes required for the most basic queries are automatically created for you. As you use and test your app, Cloud Firestore generates error messages that help you create additional indexes your app requires.

...

If you attempt a compound query with a range clause that doesn't map to an existing index, you receive an error. The error message includes a direct link to create the missing index in the Firebase console.

So, add a catch() block to the code used to execute the query and you will get the link in the error message. Note: This link is to be opened (once) via a web browser, not via the Flutter app.

Sign up to request clarification or add additional context in comments.

6 Comments

Will do in a moment. Let me get back to you.
I added try-catch block with showDialog widget in case query returns an error. Still its giving the error and not showing the link in the logs to build index for this compound query. i have build indexes for the queries and there is always a link in the logs but in this case logs are not displaying anything.
"Note: This link is to be opened (once) via a web browser, not via the Flutter app." I know about this and had build indexes multiple times in the past.
Can you show a screenshot of your indexes, taken from the console?
Also, thanks for the help as you suggested the method to identify the problem.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.