到目前为止,这是我的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 - plateNumberAnd 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数据库规范化
发布评论