Home > Back-end >  Building an Agenda / Calendar / Availability view with Firestore
Building an Agenda / Calendar / Availability view with Firestore

Time:12-06

I'm stuck. Stuck because Firestore is not (yet) capable to handle my (to me) relatively simple query. I don't want anything fancy. All I wish to get from the database are the meetings that have not ended yet. But, I would like the list to be limited to 5 items, and ordered by the starting date of the meeting, to display a small "Up next" style Agenda.

However, the following is not a valid query:

where("end", "<", now), orderBy("start", "asc"), limit(5)); 

So, how do I achieve this rather simple query for my Agenda?


And, while we're here, maybe we can dig into the other queries, too:

:: Display the last meeting (Already Over)

where("end", "<", now), orderBy("end", "desc"), limit(1))

:: Display the current meeting (Now) - Started, but not Ended.

.... ?????

:: Display the meetings which have not yet started (Next)

where("start", ">", now), orderBy("start", "asc"), limit(5))

The only thing that I can think of right now for the "current", is to grab the array of all the meetings that have ended. Grab the array of all the future meetings, and an array of all meetings. Substract the (previous) and (future) arrays from the (all) list, and I'll have the one meeting that hasn't ended, but has already started. Theres gotta be a more efficient way to do this. No?

CodePudding user response:

The common approach for this is to define buckets, and then assign each meeting to the relevant buckets.


For example, say that you show the events that are going on today, and then style the events that have already started/ended differently.

In such a scenario, you could have an array of meetings_days that contains the days that the meeting is active: meeting_days: ['2022-12-01', '2022-12-02', '2022-12-03', '2022-12-04', '2022-12-05'].

Now you can use an array-contains filter to select the events for a given day, and then determine the styling in your client-side application code. If you don't show all events (e.g. not ones that have already finished), determining the right bucket size to limit overreads while keeping the data size reasonable.

An alternative data model could be a may of the meeting days: meeting_days: { '2022-12-01': true, '2022-12-02': true, '2022-12-03': true, '2022-12-04': true, '2022-12-05': true }. Now you can do an AND type query, like finding only events that run the first 2 days of December.


The correct data model here depends on the use-cases of your app, and will likely change/evolve as your app evolves.

  • Related