Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore storage size limit how to store large arrays

I got a collection users/$userID/followers this user ID is the firebase UID so is 29 bytes long ( String sizes are calculated as the number of UTF-8 encoded bytes + 1.)

Inside each user document i got a array named followers and another named following. Both arrays contain a lot of userID's so here's the problem.

In firestore each document has a max size of 1mb so it's easy to see I'm gonna run out of space soon. My question is what's the best way to manage large arrays like this ones.

Most obvious option: Create another document, containing just a pair of new arrays to continue saving this data ( and do this in a recursive way when the limit of the document is reached).

So some better idea? Or at least how to simplify the process a little bit.

More info about size limits here: https://firebase.google.com/docs/firestore/storage-size?hl=en-419

like image 589
Kaboom Avatar asked Oct 21 '25 05:10

Kaboom


1 Answers

If you're concerned about the size of an array, you should instead split each item out of the array and make it its own document. This is the only way you will achieve massive scalability with Firestore for storing many individual items.

Yes, it will cost more. There is a cost to scalability.

like image 198
Doug Stevenson Avatar answered Oct 22 '25 18:10

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!