【发布时间】:2016-12-21 17:28:33
【问题描述】:
我刚刚开始尝试使用 Firebase。当您习惯了关系数据库时,这真是令人头疼!
我正在尝试设计一个应用程序,允许用户通过条形码或名称搜索餐食并检索卡路里数量。此外,我需要能够存储用户吃的饭菜,并最终检索用户每天、每周或每月吃的饭菜。
我在想每顿饭都有一个唯一的 ID(例如 M1234 表示比萨饼),然后我会有 2 个查找部分 - 一个按条形码,一个按名称,因此有望涵盖搜索功能。
每个用户都会将吃过的饭菜按日期存储在吃过的“表”中(Firebase 数据库中“表”的正确术语是什么?),只需按 ID 引用饭菜。
这就是我设计数据库的方式。
{
// Here are the users.
"users": {
"mchen": {
"name": "Mary Chen",
"email": "mary@chen.com",
}
},
...
},
// Here are the meals eaten by date.
"eaten": {
"mchen": {
// index Mary's meals in her profile /eaten/mchen/meals/20161217 should return 'M1234' (pizza) and 'M8765' (chips)
"meals": {
"20161217": {
"M1234": true,
"M8765": true
},
"20161218": {
"M2222": true,
"M8765": true
}
},
...
},
// Here are the meals with calorie information.
"meals": {
"M1234": {
"name": "Pizza"
"calories": 400
},
"M2222": {
"name": "Curry"
"calories": 250
},
"M8765": {
"name": "Chips"
"calories": 100
},
},
// Here is the barcode lookup
"barcode-lookup": {
"12345678": {
"id": "M1234"
},
"87654321": {
"id": "M2222"
},
"11223344": {
"id": "M8765"
}
},
// Here is the name lookup
"name-lookup": {
"Chips": {
"id": "M8765"
},
"Pizza": {
"id": "M1234"
},
"Curry": {
"id": "M2222"
}
}
}
看起来合理还是有明显缺陷?
【问题讨论】:
-
这可能会有所帮助:NoSQL Data Modeling Techniques
标签: database firebase firebase-realtime-database nosql