我已经阅读了大量的教程和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             |
    |    |            |            |            |              |                                                
    |                       |                       |
    +----+------------+------------+------------+--------------+------------------------------------------------+-----------------------+-----------------------+

我想到了这个火场结构
{
  "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 db,所以我不知道这个结构是否能够回答我们在使用关系数据库时必须回答的基本问题。
在应用程序中,我必须检索属于某个特定用户的所有旅程,并确保我必须检索属于某个特定旅程的所有阶段。
我将搜索特定用户(按名称搜索)

最佳答案

当然,对于那些在关系数据库上工作多年的程序员来说,nosql并不容易。但是就像self的sql一样,你可以在self的应用程序中做很多编程。
下面是一个例子:
你想找到“城市中心”的文本。
SQL语言
SELECT * FROM TB_STAGES WHERE text='Center of the city'
诺什
您必须遍历属性“journey”中包含的每个对象,并检查文本是否等于您要搜索的文本。
下面是一个伪代码,如何实现它:

for(i = 0; i < journey.length; i++){
   curr = journey.get(i);
   if(curr.text == search_text){
      //Do what you want
   }
}

我希望这可能有助于你理解,你总是可以自己在应用程序/客户端应用程序上制定解决方案。它并不总是最好的解决方案,但它是有效的。

07-27 19:39