Firebase Firestore Database design

Viewed 164

I'm looking for the most simply designed database structure for a given day, food type, food name and food price.

The part that is giving me trouble is, I feel like, the food name and food price need to be "tied together".

The pictures below are what I have experimented with, but I feel like I am over engineering the structure.

enter image description here

enter image description here

1 Answers

I think you need to understand the firebase ideas of collections and document better - this two level structure is often confusing to developers more familiar with SQL-like databases.

A document contains fields and potentially collections. A collection is always a collection of documents.

So in your case you might make a collection called days which contains documents 'monday','tuesday'....

the monday document might contain some other fields (the chef, the date ect) and a collection (of documents) called 'dessert'

Then each of your dessert documents might include fields for description, price etc.

So in general if you are trying to define a list of multiple similar objects your are wanting a collection of documents. If you are wanting to define fields within an object you should be looking to store them in a document.

Related