Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is storage size limitation of an array in Firestore?

I want to know what is storage size limitation of an array in Firestore. I want to create millions of index in array and want to store data as a JSON object. Array will look like:

   [{id:1,name:'shakti',userdata:2122},
   {id:0.55,name:'shakti',userdata:2122},
   {id:1.58,name:'shakti',userdata:2122},
   {id:2.58,name:'shakti',userdata:2122},
   {id:1.5,name:'shakti',userdata:2122}];

I went through the documentation but did not get any proper guide there.

like image 202
Shakti S Avatar asked Dec 01 '18 07:12

Shakti S


2 Answers

Each Firestore document can contain 1,048,576 bytes of data, a limit which includes not only the number of characters in each field name but in the name of the document itself. It's, therefore, impossible for a single document to contain an array with millions of items because there are barely a million available bytes in the document. A string array named fruits with two items "kiwi" and "orange" consumes 19 bytes and if each item in that array was a string about that long, the array would max out at about a quarter-million items.

At this point, you could distribute the array, which would simply be other arrays in other documents that spread the load (like a distributed counter described in Firestore documentation). You could randomly choose an array/document before writing to it or keep a counter that determines which array/document you write to next.

But at this point, you may be better off rethinking your data architecture because Firestore is purpose built for large collections with small documents. And—as far as the writing of this answer—there is no known limit to the size of a collection.

Whatever you choose, just be aware that Firestore charges ($) per document read and write, so fetching an array with 1,000 items will cost you 1 read, whereas fetching 1,000 documents will cost you 1,000 reads.

like image 122
liquid LFG UKRAINE Avatar answered Oct 06 '22 23:10

liquid LFG UKRAINE


Edit:

For Android, there is a library named FirestoreDocument-Android, that will help you to check against the maximum of 1 MiB (1,048,576 bytes) quota.


There is no specific limitation when it comes to Firestore arrays. The limitation comes in case of documents because in Firestore the documents have limits. So there are some limits when it comes to how much data you can put into a document. According to the official documentation regarding usage and limits:

Maximum size for a document: 1 MiB (1,048,576 bytes)

As you can see, you are limited to 1 MiB total of data in a single document. When we are talking about storing text, you can store pretty much but as your array getts bigger, be careful about this limitation.

So, as long as you store data within this limitation, there will be no problem. If you think that you might get over this limitation, I recommend you to store that data in a collection. In this case there are no limitations. You can store as many documents as you want.

like image 33
Alex Mamo Avatar answered Oct 06 '22 23:10

Alex Mamo