Reputation: 833
I'm in the process where I need to store data under a specific users account with Firebase. I'm fairly new working with the backend and I'm primarily looking for a second option before I start typing away.
This is how I currently have it structured:
Providers
City
Cincinnati
Company 1
Jobs
History
Company 2
Jobs
History
Columbus
Company 1
Company 2
My thought is it would be better to have each company listed within a specific city node when a user is requesting from that city. However, if the city was at the first level then we'd have to go through the city first. But instead of having the city at the higher level we can store the cities their in under the companies node essentially in an array.
So here's the user flow:
The user makes a request based on their location (city). The provider accepts that specific job which moves into the 'jobs' node. Once the job is complete it then moves into their 'history' node.
My question:
Should I keep the structure as is or place the city within the companies node?
Upvotes: 0
Views: 54
Reputation: 13129
Your structure is right, as city is your primary key in this case, since a company has a city, you will need to specify first the city where you want to pull companies from. I assume that this structure is the right way to go to solve your problem.
If your parent node is not City and just the name of the cities you will end up with a lot of children in your main tree, and that is what you don't want, you want to structure your database in order to do it readable when data is big enough.
PS: Think in scalability, if you think this way you end up with a good organized database, now, as you are doing it it's OK, but if you have another doubt, think in this way to improve your structure.
Upvotes: 1