Pregunta

I have recently started to use Firebase. However, since I am not familiar with NoSQL databases I am having a little trouble structurizing it.

I am developing a timesheet application, several users can input their starting and ending hours each day they go to work and it will be saved into a database.

At the moment the structure of my firebase looks like this :

http://imgur.com/tnojU8x

However, I am having some trouble accessing this data in my application. On top of that this just doesn't feel right. First I wanted to just add a new entry under 'timesheet' every time a user inputs something, but obviously, I do not want a user to be able to add 2 entries for one day either.

I know that there's probably some complex way to stop a user from doing this, but I feel that this could all be solved in an easier way if I just saw how I should best structure this database.

Later I want to loop through all the days in the current month for a specific user to show him in a table all his starting/ending hours for each day of the month.

Update: I was thinking about denormalizing my database, but would that really help anything?

¿Fue útil?

Solución

You should read this blog post, written by the Firebase team.

TL;DR is that you should denormalize your data because Firebase is optimized for certain kinds of operations (you don't need to fully understand the nitty gritty of that optimization to use Firebase properly).

"I am having some trouble accessing this data in my application"

What kind of trouble?

"I do not want a user to be able to add 2 entries for one day either."

That isn't really a denormalization problem; with your structure now, you could just check a path for null.

new Firebase('path/to/timesheets/April/'+ queryDate) === null, where queryDate is the date you want to check for.

If the above returns true, your user hasn't submitted a timesheet. If so, you shouldn't allow them to.

"I want to loop through all the days in the current month for a specific user to show him in a table all his starting/ending hours for each day of the month."

You can! Iterate with a for loop through all the values nested under the object that's returned when you ask for new Firebase("path/to/April").

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top