【发布时间】:2018-07-31 08:24:41
【问题描述】:
我已经阅读了大量的教程和 stackoverflow 问答,并开始尝试为 Firebase 设计数据库结构。我试图让它保持平坦(这似乎是一个非常重要的考虑因素)。同时我不知道我将应用于 FireBase 数据库的所有可能的查询(在这篇文章的结尾我给出了一些基本的例子)。因此,我正在寻求已经使用 Firebase 并遇到来自关系数据库的人员的主要问题的人的帮助
给出如下Mysql结构
TB_USER
+----+--------+-------------+---------------+-----------------------------+------------------------+------------+
| id | name | bio | link | avatar | userId | created_at |
+----+--------+-------------+---------------+-----------------------------+------------------------+------------+
| 1 | Fabian | bla...bla.. | www.site.com | img_on_the_Server.jpg | StringFromAuthFBGoogle | 20-02-2018 |
| 2 | Sarah | bla...bla.. | www.sarah.com | img_on_the_Server_Sarah.jpg | StringFromAuthFBGoogle | 18-02-2018 |
| 3 | Carl | bla...bla.. | www.carl.com | img_on_the_Server_Carl.jpg | StringFromAuthFBGoogle | 14-02-2018 |
+----+--------+-------------+---------------+-----------------------------+------------------------+------------+
TB_JOURNEYS
+----+----------------------+----------------------+--------+------------+
| id | journey_name | description | iduser | created_at |
+----+----------------------+----------------------+--------+------------+
| 28 | Traveling to India | desc of India | 2 | 21-02-2018 |
| 34 | A week in China | desc of China | 1 | 21-02-2018 |
| 46 | South America by car | incredible adventure | 3 | 22-02-2018 |
+----+----------------------+----------------------+--------+------------+
TB_STAGES
+----+------------+------------+------------+--------------+------------------------------------------------+-----------------------+-----------------------+
| id | id_journey | date | latitude | longitude | text | picture | video |
+----+------------+------------+------------+--------------+------------------------------------------------+-----------------------+-----------------------+
| 10 | 28 | 20-12-2017 | 46.3991665 | -117.0484223 | Fantastic day | image_of_that_day.jpg | video_of_that_day.mp4 |
| 20 | 28 | 23-12-2017 | 14.6082829 | -90.5528772 | Another beautiful day walking through the city | img_art.jpg | |
| 30 | 46 | 01-01-2018 | 45.462889 | 9.0376466 | Center of the city | pic.jpg | video.mp4 |
| | | | | |
| | |
+----+------------+------------+------------+--------------+------------------------------------------------+-----------------------+-----------------------+
我想出了这个 FireBase 结构
{
"users": {
"1": {
"name": "Fabian",
"bio": "bla...bla",
"link": "www.site.com",
"avatar": "img_on_the_Server.jpg",
"userID": "StringFromAuthFBGoogle",
"created_at": "20-02-2018"
},
"2": {
"name": "Sarah",
"bio": "bla...bla",
"link": "www.sarah.com",
"avatar": "img_on_the_Server_Sarah.jpg",
"userID": "StringFromAuthFBGoogle",
"created_at": "18-02-2018"
},
"3": {
"name": "Carl",
"bio": "bla...bla",
"link": "www.carl.com",
"avatar": "img_on_the_Server_Carl.jpg",
"userID": "StringFromAuthFBGoogle",
"created_at": "14-02-2018"
}
},
"journeys": {
"28":{
"journey_name": "Traveling to India",
"description": "desc of India ",
"created_at": "21-02-2018",
"iduser": 2
},
"34": {
"journey_name": "A week in China ",
"description": "desc of China ",
"created_at": "21-02-2018",
"iduser": 1
},
"46":{
"journey_name": "South America by car",
"description": "incredible adventure",
"created_at": "22-02-2018",
"iduser": 3
}
},
"stages": {
"10": {
"id_journey": 28,
"date": "20-12-2017",
"latitude": "46.3991665",
"longitude": "-117.0484223",
"text": "Fantastic day ",
"picture": "image_of_that_day.jpg",
"video": "video_of_that_day.mp4"
},
"20": {
"id_journey": 28,
"date": "23-12-2017",
"latitude": "14.6082829",
"longitude": "-90.5528772",
"text": "Another beautiful day walking through the city",
"picture": "img_art.jpg"
},
"30": {
"id_journey": 46,
"date": "01-01-2018",
"latitude": "45.462889",
"longitude": "9.0376466",
"text": "Center of the city",
"picture": "pic.jpg",
"video": "video.mp4"
}
}
}
真正的问题是我从未使用过 NOSQL 数据库,所以我不知道该结构是否可以回答我们在使用关系数据库时必须回答的基本问题。 在应用程序中,我必须检索属于特定用户的所有旅程,并且肯定我必须检索属于特定旅程的所有阶段。 我将搜索特定用户(按名称搜索)
【问题讨论】:
标签: android mysql database firebase-realtime-database