Stackoverflower
Stackoverflower

Reputation: 322

Does a heavy document take much time in load from Firestore?

I am using both Firebase Database and Firestore in my app. I store users data like name, email, uid etc small details in documents of a collection as Users in firestore. It works perfectly. I made a node as Friends in firebase database to store friends list of a user. So whenever user open the app, it calls his information from Users from firestore and also his friends list from Friends from firebase database.

Now the thing is by this way it calls data from the Firestore and the Firebase database. So it means they are 2 requests/reads, one to Friends node and other to a document from Users collection. I think it would be better if i store friends list in Users document as an Array. So i will get only 1 read in Firestore. But i think that when the arrays of his friends list increases by 100+ elements. And also there are one or two more array lists like that. So will it take much time in retrieving a document from Users collection? or not? And which will be a better approach?

Here are the images of my current database structure as Users and Friends.

Upvotes: 3

Views: 1718

Answers (2)

Faraz Rasool
Faraz Rasool

Reputation: 289

I built a chat app in flutter with firebase using mapping for each chat Text(only one doc was used in chat between 2 users). I observed that after I filled 1MB of data in doc, my mobile downloaded the chat history at 10-12 kbps from firebase. Maybe the speed was a coincidence but I am sure that as your data grows in a single firestore doc, the mobile app does not bursty download the whole document simultaneously, instead it downloads at a much slower speed. Please correct me If I am wrong.

Upvotes: 0

Farid Shumbar
Farid Shumbar

Reputation: 1420

As per the Firestore usage and limits, the maximum size of a document is 1 MiB.

It means that as long as your user documents don't exceed the size limit, you can store friends data in arrays without a problem.

If you are planning to exceed the threshold, you may want to look for other options like creating subcollections to scale better as size of the subcollection doesn't affect the parent document's size in any way.

Upvotes: 1

Related Questions