3
votes

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.

1
Please don't include Realtime Database as a link or image. If the link breaks it would invalidate the question. Include those in the question as a short section of text. To get your Firebase structure, use the Firebase console->Export JSON and copy and paste a snippet of your structure.Jay
It seems you're asking for our opinion about what's best for YOUR app. Without understanding the entire use case, it would be impossible to answer. If you are having difficulty with a section of code, thats is something we can help with. Please take a moment and review How do I ask a good question? and How to create a Minimal, Complete, and Verifiable exampleJay
It's also not clear why you are using two different databases; using one would make the app easier to maintain and control. All Firebase products are very fast and getting information from Firebase depends on your internet and the amount of data. However, and this is important, generally speaking, whether your database has 10 or 10,000 documents/nodes if you retrieve 10, it will be about the same speed regardless of the overall amount of data. e.g. the speed at which you get data is not dependent on the total amount of stored data - it's more dependent on how much data you're getting from it.Jay
It's not clear what's being asked - let me explain why. As mentioned in the answer, Firestore documents have a maximum size of 1 MiB. That's the amount of data, regardless of configuration, that can be in a document. A document of that size, for example, loads in .083 seconds with a fast internet connection. So if there's less data it could shave off .002 seconds. As you can see, it's not really a number that has any kind of impact. Additionally a document having 100 fields is nothing; keeping in mind the 1MiB limit. So what's the actual issue? Can you clarify and provide a specific example?Jay
Oh oh - and if you have not read it, please check out this brilliant Firestore Overview from @dougstevenson top 10 things to know about Firestore. It's kinda unrelated to the question but you mentioned large size arrays and there's has some fantastic pointers on organizing your data within Firestore.Jay

1 Answers

1
votes

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.