最佳实践数据设计在firebase [英] best practice data design in firebase

查看:135
本文介绍了最佳实践数据设计在firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何构建以下方案的数据?



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



用户名(谁在线订购此餐厅菜单)



Restaurant_name



说明



位置



预计送货



一个餐厅的多个菜单)



<$ p $

restaurant:{
username:{
restaurant_name:KFC Restaurant,
description:
估计交货:1小时/公里,
距离:20公里外,
位置:加德满都,
星号最多5,
menus:{
menu:{
item:buff momo,
price:$ 5 b $ brating:ratingup 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
}
}
}

} $ b b

解决方案

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



如果在您的网站中要显示所有餐厅的列表,当您点击餐厅显示他们提供的菜单列表时,不是一个好主意。



因为根据文档:


我们在Firebase数据库中读取一个数据节点,我们也检索其所有的孩子!


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



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

 restaurant:{
$ username:{
restaurant_name:KFC餐厅,
description:餐厅简介,
预计送货:1小时/ $ bdistance:20km away,
location:Kathmandu,
rating:rating star up to 5,

}
}

menus:{
$ username:{
menu:{
item:buff momo,
price:$ 5,
rating:rating star to 5
},
menu:{
item:Fried鸡,
价格:$ 10,
评级:评级星最多5
},
菜单:{
item:BBQ,
price:$ 20,
rating:rating star to 5
}
}
} b $ b


How could i structure data for following scenario?

There is an app called Food Ordering System. It contains

Username(Who is registering this restaurant menus for online order)

Restaurant_name

Description

Location

Estimated Delivery

Menu(Has multiple menus for one restaurant)

My design

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

}

Is my design the best practice design?

解决方案

It actually depends on what you want to do with this data.

If in your website you want to show a list of all restaurant and when you click on restaurant show the list of menu they are offering, storing the menu inside the restaurant might not be a good idea.

Because according to the doc :

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

(the old one) https://www.firebase.com/docs/rest/guide/structuring-data.html#section-denormalizing-data

Also imagine if you want to do a search bar and look for menu (like chicken nuggets) and return the list of restaurant offering this I would design your database this way :

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

这篇关于最佳实践数据设计在firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆