uksz
uksz

Reputation: 18719

Firestore console - document size limit

I am wondering what is the maximum size of the document that is stored on Firestore? I have a sample json that I am trying to store in Firestore as document, however when I am trying to read it from console, my web browser freezes. There is no problem when reading it from query. Sample of the document is pasted below:

'0':    249999,
'5':    249998,
'10':   249997,
'15':   249996,
'20':   249995,
'25':   249994,

The rest of the document content can be found here.

Any idea why the console may freeze?

Upvotes: 0

Views: 2944

Answers (2)

Gastón Saillén
Gastón Saillén

Reputation: 13159

There is a cool library that you can use to determine the sizes of your documents and more information about it.

Check it out: https://github.com/alexmamo/FirestoreDocument-Android/tree/master/firestore-document

This library will tell you your document sizes and you can check if a document is less than the current quota of 1Mbit

Edit

Here you can see how to get the document size with this library, is pretty easy, first you build up a reference to the document you want to get size for, then just use .getSize() on that DocumentReference or QueryDocumentSnapshot

 myTaskIdRef.get().addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                DocumentSnapshot document = task.getResult();
                if (document.exists()) {
                    int documentSize = firestoreDocument.getSize(document);
                    String textToDisplay = "Size: " + documentSize + " bytes";
                    docSizeTextView.setText(textToDisplay);
                }
            }
        });

Alternatively this library has a method that returns a boolean value if the document itself is less than 1Mbit

  /**
     * @param document The document that we want to know if it's less than 1 Mebibyte
     * @return True if the document is less than 1,048,576 bytes else false.
     */
    public boolean isDocumentSizeLessThanOneMebibyte(DocumentSnapshot document) {
        return getSize(document) < ONE_MEBIBYTE;
    }

So we can do from the code above

if(isDocumentSizeLessThanOneMebibyte(document)) { 
...
}

Each time you do a .getSize() it will check if the document is not nearly hitting the quota, so the library warns you about the current size if it's too high.

Upvotes: 0

Frank van Puffelen
Frank van Puffelen

Reputation: 600006

The maximum size of a document is 1MB. See the Firestore documentation on quota and limits.

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

Upvotes: 2

Related Questions