Firebase数据库规范化

编程入门 行业动态 更新时间:2024-10-27 22:21:05
本文介绍了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数据库规范化

本文发布于:2023-11-22 09:15:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616840.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!