I'm migrating my relational database to Firebase. In general, I have a planner for workers. They can add an item ('appointment') to their schedule. I've read the FireBase documentation, and found a section on indexing.
So I've created following structure (date = YYYYMMDD
and time = HHMMSS
):
{
appointments :
'id1' : { 'date' : '20141207', 'time' : '170000', worker : 'worker1' },
'id2' : { 'date' : '20141208', 'time' : '170000', worker : 'worker1' }
}
I've added an index for date, time and worker, to be able to query data like this (e.g. fetch all appointments for today):
curl -X GET 'https://myapp.firebaseio.com/appointments.json?orderBy="date"&equalsTo="20141207"'
This works as expected and does the job well. The problem is, the number of appointments can grow exponentially (about a year from now, there could be 100000+ appointments). Is it a good approach to use these indexes? Another option would be to store the date and time also separately, like this:
{
'20141207' :
{ '170000' : { 'id1' : true } },
'20141208' :
{ '170000' : { 'id2' : true } }
}
In order to ensure that appointments can be fetched per day very fast. Or is FireBase able to handle this just using indexes?