Firebase数据库规范化 [英] Firebase Database Normalization

查看:156
本文介绍了Firebase数据库规范化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我做了一个简单的应用程序,一个三轮车巡逻应用程序,你可以报告鲁莽的三轮车司机(我们这里没有一个问题在我们的城市)登录和填写表格。报表包含:

   -  created_at 
- description
- lat
- lng
- plateNumber

到目前为止,这是我的json的结构:





有没有更干净的方法来做到这一点?到目前为止,它的工作,虽然例如,我想通过 plateNumber 的所有报告,我认为这将是棘手。



PS:我知道这不是一个关系数据库,虽然我是开放的建议

规范化数据库...当我遇到这个问题时,我停止编写代码并开始考虑我的应用程序/ web。 ...


  • 我想显示所有报表的列表,按板块排序的另一个列表并由其他人订购

  • 或者在所有报告列表中按板块

  • 排序


如果您的答案是第一个,那么您需要生成节点作为索引,如下所示:

 报告{
report_id {
created_at:
描述:
lat:
lang:
locati on:
plate_number:
}
}
reports_idx_plate {
plate_number1 {
report_id1:true
report_id2: true
report_id3:true
report_id4:true
}
}

如果您的答案是第二个,那么您的最佳选择就是这样:

 报告{
plate_number {
report_id {
created_at:
description:
lat:
lang:
location:
plate_number:
}
}
}

在简历中,如果您需要从子节点获取列表,则需要规范化节点并生成节点作为索引。
让我知道,如果我已经帮助你,并且编程的很好!

So I made a simple app, a Tricycle Patrol app which you can report reckless tricycle drivers (no 1 problem here in our city) by logging in and filling up forms. The report form contains:

- created_at
- description
- lat
- lng
- plateNumber

And so far, this is the structure of my json:

Is there a cleaner way to do this? So far it works though for example I want to get all reports by plateNumber I think it would be tricky.

Any suggestions would be much appreciated.

PS: I know it's not a relational database though I'm open for suggestions

解决方案

Now as you say you need normalize database ... When I have this problem, I stop writing code and start thinking about my application / web ...

  • I want to show a list of all reports, another list sorted by plate and ordered by others?
  • Or in all lists of reports are sorted by plate?

If your answer is the first, then you need to generate nodes as indexes, like these:

reports{
    report_id{
        created_at:" "
        description:" "
        lat:" "
        lang:" "
        location:" "
        plate_number:" "
    }
}
reports_idx_plate{
    plate_number1{
        report_id1:"true"
        report_id2:"true"
        report_id3:"true"
        report_id4:"true"
    }
}

If your answer is the second one, then your best option is this one:

reports{
    plate_number{
         report_id{
            created_at:" "
            description:" "
            lat:" "
            lang:" "
            location:" "
            plate_number:" "
        }
    }
}

In resume if you need to get list from child node, you need to normalize the nodes and generate the nodes as index. Let me know if I have helped you and good programming!

这篇关于Firebase数据库规范化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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