简体   繁体   中英

Firebase: Operation was rejected because the system is not in a state required for the operation's execution

I'm starting working with collections groups in Firebase and I cannot make it work. I need to filter it by billable leases:

users/portfolios/rents

Here I have a property which is a list of leases (not a collection, just a property) called leases with some properties like billable :

在此处输入图像描述

I have created a single-field index:

在此处输入图像描述

And also a composite index (not sure if I also need it):

在此处输入图像描述

This is my query using Flutter:

FirebaseFirestore.instance
        .collectionGroup('rents')
        .where('billable', isEqualTo: true)
        .get()
        .then((QuerySnapshot querySnapshot) {
      for (var doc in querySnapshot.docs) {
        print(doc);
      }
    });

The error I get is:

Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console.

It's not indexed already?

For the query in your question you'll need a collection group index on the finished field of the rents collection group, which I don't see in any of the screenshots you shared.


From the screenshot of a document you linked in the comments here:

So billable is a value in each item of the leases array field. There is no way to query on such a single value in an array field, as the == operator checks whether the entire array field is the same as the value you specify, and the arrayContains operator checks if any array item matches the entire value you specify.

The common workaround is to extra the value you want to query on to a top-level field, either an array field or a single boolean. For example, if you add a field hasAnyBillableLeases to the rents document, you can query on that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM