So let’s say you have 3 or more courses like c#, c++, java, and Python and you would like to implement some chatting feature on each course. Would you create like different collections to store their messages separately in cloud firestore then use where clause on let’s say field ==’python’?
If subcollection could it be created automatically? (on first message sent maybe)
2
Answers
For example you have 10 courses with 100 messages each the data it would send to each call is 1000 entries and if you have a separate collection then you get only 100 entries. It is always better to reduce the amount of data passed
Yes, you can do that. A possible Firestore schema might look like this:
In this way, you can simply get the messages that correspond to a single course, by pointing exactly to the "chats" sub-collection, that exists, within that course. If you however want to get all messages, from all courses, a collection group query will be required, which in code it looks like this:
You can also create a top-level collection that can look like this:
From each, you can get all messages of a particular course using
field =='python'
.Yes, this is possible. Simply create the corresponding reference and add the first document (chat) to the "chats" collection or sub-collection.