I'm trying to create a recipe backend to test firestore and so far I've managed to get the CRUD operations working for the users, authentication & hashing passwords. Now I wanted to make it so there are two tables: ingredients and recipes and was wondering the best way to go about this?
My plan:
ingredients with all the apples, pears, rice, etc. and fill up the table as usual.recipes with an ingredients array that just points to the ingredientId of each of the ingredients. (one to many)review on the recipe (one to many)I've done something similar in MongoDb before but I can't find anything written about firestore + Node.js on this. For reference, in MongoDb I would do something like this for the `reviews:
review: {
type: mongoose.Schema.ObjectId,
ref: 'Recipe',
required: [true, 'Review must belong to a Recipe!']
},
My idea is that I structure it like:
Recipe: {
name: 'Yummy Cake',
cooking time: '15 mins',
... other fields,
ingredients: [
{ ingredientId1: '5',
ingredientId2: '25',
...
}
],
reviews: [
{ userId1: '4',
userId2: '3',
}
]
}
But I don't really know how to write that in a firestore-friendly manner. Any help is greatly appreciated! Also I'm using firebase-admin as the package.