I am building an angular component for handling custom calendars and events. Once an event is created I save the given data to the firestore database as single documents.
Document sample :
{
"name" : "test event",
"description" :"sample test event for check",
"startdate":"8/12/2021",
"enddate":"8/12/2021",
"color":"#11111",
"userid":"user1"
}
So on creating each event the similar data structure will be saved as individual documents. We can filter the custom calendar with a date range and also support showing multiple user events in a single calendar.
But using the above document structure, when we try to fetch a large amount of data it leads to higher costing to the server. How can I organize these data on an individual basis or else? Can Anyone suggest your opinion about this?
This structure should be good for the use case as it won't hit any per document limit (storing events in an array may hit 1 MB per document size limit) and you can easily execute most of the queries.
How can I organize these data on an individual basis or else?
You have the userid field in document and user's events can be filtered using .where("userid", "==", curUserId). Other way would be to use sub-collections:
users -> {userId} -> events -> {eventId}
(col) (doc) (col) (doc)
This way you won't have to store user's UID in every document as it is already grouped in sub-collections.
when we try to fetch a large amount of data it leads to higher costing to the server
Firestore costs are totally based on your usage. If your application has a lots of users then the costs will be higher.