Hi everybody,
This is a fun problem. I have a novel solution that Jason didn't mention, and I thought I would throw it into the discussion even though its probably not the route you want to take.
Your schema would be something like:
{
name: String,
range: Array,
....
}
The idea being that you would give each record an array that represented bins of the times in a day. As an example, you could choose to divide each day into hours and have Arrays with length 24. Then a user who was available from 8am to 8 pm would look like
[ 0, // not available between 12am and 1am
0, // not available between 1am and 2am
0, // not available between 2am and 3am
0, // not available between 3am and 4am
0, // etc...
0,
0,
0,
1, // AVAILABLE between 8am and 9am
1, // etc...
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0 ]
With this solution your query is simplified to just checking if the current hour is a 1. This also makes it easy to have more complex ranges of time, e.g. if you don't want to be contacted during lunch or you are available after dinner each night etc...
If you want to decrease the size of the bins the Arrays will quickly become much larger, and potentially make this a poor choice.
There is an over two year old mongodb ticket that would add better support for bitwise operators
https://jira.mongodb.org/browse/SERVER-3518. If this landed you could reduce the size requirements for implementing something like this significantly and potentially use a strategy similar to above without the overhead of huge Arrays of numbers.
Anyway, like I said above, this may not be a useful solution for you, but a fun one to think about :)
-Joe