Too bad the aggregation framework didn’t work out.
As for your question, I don’t think it’s a pattern to have too many subscriptions like that, especially if each one returns a single document. But I could be wrong.
So it looks like you have too many Timeslots and it could be difficult to monitor. I’d not use a timeslot collection. Just an Appointments one. This would have a field for the date (doesn’t matter what time) and a string field with a predefined slot, like “9-10”. This is what it all would look like. (I haven’t used React yet so this uses Blaze):
2 templates( or components). One representing a day and one for the timeslots for that day:
<template name='day'>
<h1>{{day}}<h1>
{{> timeslots}}
</template>
<template name="timeslots">
<h2>Here's today...</h2>
<ul>
<li>8-9 is {{isAvailable "8-9"}}</li>
<li>9-10 is {{isAvailable "9-10"}}</li>
<li>10-11 is {{isAvailable "10-11"}}</li>
</ul>
</template>
Say the user wants to check what’s available for December 18, 2015.
First, you subscribe to the all Appointments with a date of December 18, 2015 at 00h00m00s. An Appointment document would look like this.
_id: 1d345hjk5sdf,
date: "Thu Dec 18 2015 00:00:00 GMT+0100", // Doesn't matter what time, just the date.
slot: "9-10" // The slot is a predefined string.
On the client you render the “day” template. Inside there’s the timeslots template. This is what the slot.js would look like.
Template.timeslots.helpers({
isAvailable(slot) {
// This gets the date from the parent template's context
// You would have set this context when you render your "day" template(s)
const date = Template.parentData([1]).date;
// slot is passed from the template and is used here to search
Appointments.findOne({date: today, slot: slot}) ? "taken" : "available"
}
})
I hope this makes sense. So to sum up, you render multiple day templates, depending on the range users wanna see. The subscription is just one and it monitors all Appointments within the date range. Each day template will display its timeslots. The availability for each day is a combination of a day plus a timeslot string .
Let me know if you have questions or if I’ve gone crazy