Firebase Database Normalization

前端 未结 2 832
遇见更好的自我
遇见更好的自我 2021-01-20 03:58

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 f

2条回答
  •  無奈伤痛
    2021-01-20 04:58

    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!

提交回复
热议问题