gpt4 book ai didi

javascript - Firebase 中的最佳实践数据设计

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:22 24 4
gpt4 key购买 nike

我如何为以下场景构建数据?

有一个名为 Food Ordering System 的应用程序。它包含

用户名(谁在注册这家餐厅的在线订单菜单)

餐厅名称

描述

位置

预计送达时间

菜单(一家餐厅有多个菜单)

我的设计

  "restaurant":{
"username":{
"restaurant_name":"KFC Restaurant",
"description":"short description on restaurant",
"estimated delivery":"1hour/km",
"distance":"20km away",
"location":"Kathmandu",
"rating":"rating star up to 5",
"menus":{
"menu":{
"item":"buff momo",
"price":"$5",
"rating":"rating star up to 5"
},
"menu":{
"item":"Fried Chicken",
"price":"$10",
"rating":"rating star up to 5"
},
"menu":{
"item":"BBQ",
"price":"$20",
"rating":"rating star up to 5"
}
}
}

}

我的设计是最佳实践设计吗?

最佳答案

这实际上取决于你想用这些数据做什么。

如果您希望在您的网站中显示所有餐厅的列表,并且当您点击餐厅时显示他们提供的菜单列表,那么将菜单存储在餐厅内可能不是一个好主意。

因为根据文档:

When we read a data node in our Firebase database, we also retrieve all of its children!

(旧的)https://www.firebase.com/docs/rest/guide/structuring-data.html#section-denormalizing-data

另外,想象一下,如果你想做一个搜索栏并寻找一个菜单(比如鸡 block )并返回提供这个的餐厅列表,我会这样设计你的数据库:

"restaurant":{
"$username":{
"restaurant_name":"KFC Restaurant",
"description":"short description on restaurant",
"estimated delivery":"1hour/km",
"distance":"20km away",
"location":"Kathmandu",
"rating":"rating star up to 5",
...
}
}

"menus":{
"$username" : {
"menu":{
"item":"buff momo",
"price":"$5",
"rating":"rating star up to 5"
},
"menu":{
"item":"Fried Chicken",
"price":"$10",
"rating":"rating star up to 5"
},
"menu":{
"item":"BBQ",
"price":"$20",
"rating":"rating star up to 5"
}
}
}

关于javascript - Firebase 中的最佳实践数据设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37345365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com