我正在制作一个获取配料的应用程序,而不是显示可以用这些配料制成的食谱。这些食谱将存储在火源中。 我正在考虑采用的结构如下:
{
"description" : "Some description",
"name" : "Recipe name",
"idRecipe" : 1,
"ingredients" : {
"ingredient1" : "tomato",
"ingredient2" : "pepper",
.
.
.
"ingredient10": "cheese",
},
"numOfPersons" : 2,
}
如何“查询”具有匹配成分的食谱,还是应该更改食谱的结构?
答案 0 :(得分:1)
您可以将模型更改为这样:
{
"description" : "Some description",
"name" : "Recipe name",
"idRecipe" : 1,
"ingredients" : {
"tomato" : true,
"pepper" : true,
.
.
.
"cheese": true
},
"numOfPersons" : 2,
}
然后您可以使用多个where
queries来获得此食谱,例如:
query = recipeRef.where("ingredients.tomato", "==", true).where("ingredients.pepper", "==", true).where("ingredients.cheese", "==", true);