Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if the document size exceeds 1MB in firestore?

I am using cloud firestore in my android chat application, I want to store the all messages (incoming and outgoing, basically maintaining message history for a device) in array-list of a document, but the maximum size of a document is 1MB. What would happen if the size of document exceeds 1MB when I am trying to store the message

Is there any API is available to get the size of the document before writing?

Please suggest me better way to maintain message history using firestore?

like image 261
Santhosh Avatar asked Jan 28 '19 10:01

Santhosh


1 Answers

If the document size exceeds 1MB. It will throw an error like this "Error: 3 INVALID_ARGUMENT: A document cannot be written because it exceeds the maximum size allowed."

Me too think that there is no API for getting the size of the document. One way is that, You can get the entire data from collection and stringify that, remove the white spaces and count the number of chars then add a buffer value based on the documentation https://firebase.google.com/docs/firestore/storage-size

like image 166
Pravin Prabhu Avatar answered Oct 15 '22 09:10

Pravin Prabhu