Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Firestore 'in' Operator Workaround

I am using google cloud firestore as a database for a flutter application. My code requires that I make a request containing '.where("X", "in", "very-long-list")' to the database. The issue that arises is an 'in' operator can only combine up to 10 equality clauses while my list is of variable length that may end up significantly larger than 10. I am looking for possible workaround to the issue.

An example statement:

citiesRef.where("state", "in", "[list-of-1000]");

Edit: To give additional context, my project is a social media application where users have friends. The database is to being restructured such that a user document has a subcollection 'friends' with a document containing their user id. A user document also has a collection called posts with references to a chronologically ordered post collection. Within the posts collection, each post document has a document containing their UID. To create a user's feed, the post collection is to be referenced and filtered using '.where["UID", "in", ["List-of_friend-UIDs"])'. If you know of a better structure I am very open to restructuring my database.

like image 480
FANCY_HOOMAN Avatar asked Mar 24 '26 14:03

FANCY_HOOMAN


1 Answers

If you must use more than 10 items in an "in" query, then you will need to break it up into smaller lists of 10, perform 1 query for each batch of 10, and merge the results.

like image 172
Doug Stevenson Avatar answered Mar 26 '26 11:03

Doug Stevenson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!