1

I have id list like this;

List<dynamic> saveIDList = []; The values ​​in this list change according to the id saved by the user.

I try to show the posts saved by the user. So I create a query like this;

 Query saveIDRef = _firestore
              .collectionGroup("Posts")
              .where("postID", whereIn: saveIDList);

After creating this query, I call the saveIDRef in the stream builder. So far, there is no problem in my code, it works properly, but when the length of the saveIDlist exceeds 10, I get a warning.

It is not possible for me to change my database form or the way I query my saveIDList, how can I solve this problem?

I tried different solutions but it didn't work.

For Example I create chunk list like this;

var chunks = [];

for (var i = 0; i < saveIDList.length; i += 10) {
      chunks.add(saveIDList.sublist(
          i, i + 10 > saveIDList.length ? saveIDList.length : i + 10));
    }

and I seperated values in saveIDList then I used chunks in whereIN query like this;

 Query saveIDRef = _firestore
                  .collectionGroup("Posts")
                  .where("postID", whereIn: chunks);

But that didn't work either. When I query chunks list like this;

Query saveIDRef = _firestore
                      .collectionGroup("Posts")
                      .where("postID", whereIn: chunks[0]);

it works. But I want to Query all elements in chunks list not the only first element of chunks list. When I put this code in to the for loop, I get error of whereIN query cannot use more than once.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Rkdio
  • 153
  • 2
  • 13
  • 1
    This might help https://stackoverflow.com/questions/61893744/how-can-i-deal-with-the-firestore-wherein-limit-of-10-when-using-a-switch-stream – ahmetakil Dec 13 '21 at 13:55
  • I checked but I cant found a side that can be adapted to my problem. – Rkdio Dec 13 '21 at 15:01

1 Answers1

2

As stated in the Firebase documentation regarding the simple and compound queries in Cloud Firestore, there are some limitations on the logical queries:

Cloud Firestore provides limited support for logical OR queries. The in, and array-contains-any operators support a logical OR of up to 10 equality (==) or array-contains conditions on a single field. For other cases, create a separate query for each OR condition and merge the query results in your app.

Thus a possible solution would be to create chunks of your list and query those chunks separately as you have tried. For instance you can use the List subList method of the List object to create those sublists or chunks.

llompalles
  • 3,072
  • 11
  • 20