如何为以下场景构建数据?
有一个叫“食物订购系统”的应用程序。它包含
用户名(正在注册此餐厅菜单以便在线订购)
餐厅名称
说明
位置
预计交货
菜单(一家餐厅有多个菜单)
我的设计

  "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"
            }
        }
    }

}

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

最佳答案

这实际上取决于你想用这些数据做什么。
如果你想在你的网站上显示所有餐厅的列表,当你点击Restaurant显示他们提供的菜单列表时,将菜单存放在餐厅内可能不是一个好主意。
因为据医生说:
当我们在firebase数据库中读取一个数据节点时,我们也会检索它的所有子节点!
(旧的)https://www.firebase.com/docs/rest/guide/structuring-data.html#section-denormalizing-data
另外,想象一下,如果你想做一个搜索栏,寻找一份菜单(如鸡块),并返回提供此功能的餐厅列表,我会这样设计你的数据库:

"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/

10-09 07:26
查看更多