Skip to content Skip to sidebar Skip to footer

How Deep We Can Query In Firestore?

I am just looking for the answer to design the database on Firestore. I have subcollections at 4 and 5 levels from root collection and at this level can the chat system be applied

Solution 1:

Realtime Database has a limitation of 32 nodes. In Firestore, however, it's much better. As per the documentation:

Documents in subcollections can contain subcollections as well, allowing you to further nest data. You can nest data up to 100 levels deep.

So the limit is 100 levels deep. You could have subcollections inside subcollections for up to 100 levels deep. Here is another quote if you don't know how subcollections work:

Subcollections allow you to structure data hierarchically, making data easier to access.

If you want to learn more about the limitations or about the firestore data model look at the documentation here: https://firebase.google.com/docs/firestore/data-model

As for your question:

I have subcollections at 4 and 5 levels from root collection and at this level can the chat system be applied and queried easily or not?

Yes, you can query that information. Of course with Firestore these queries are really fast. But you need to take into consideration that nesting your data too deep will affect the speed of your queries(because of the speed of queries nobody will even notice something, it's basically like picoseconds; you can only notice if you are running queries benchmark test in great precision). Take into consideration, that the speed of your queries don't depend on the size of your request data, but on the size of your return data.

Solution 2:

How deep we can query in Firestore?

You can chain in depth up to a maximum of 100 subcollections. As per the official documentation regarding usage and limits.

Maximum depth of subcollections: 100

Regarding:

I have subcollections at 4 and 5 levels from root collection and at this level can the chat system be applied and queried easily or not?

Please note that Firestore can as quickly look up a collection at level 1 as it can at level 100. So for a regular database, depth should not be a factor that affects speed on a technical level. So in your case, there is nothing to worry about.

If you want to have a clean architecture, it's best to have the database as flatten as you can but if your requirements are to use nested subcollections, you can go ahead with that.

Post a Comment for "How Deep We Can Query In Firestore?"