Correct Way To Store Users In Firebase Database

前端 未结 1 619
长情又很酷
长情又很酷 2021-01-06 06:54

currently I am working on a Database Layout for my Firebase Database. I am looking through many different tutorials on how the layouts should look, but I am getting a bit co

相关标签:
1条回答
  • 2021-01-06 07:13

    Firebase push ids are great when you have a collection that you want to order chronologically, where the individual items don't have a natural key. So a list of blog posts, chat messages, etc.

    But when items have a natural key, it is usually better to store them under that natural key. Users have a unique id, usually referred to as their uid. Unless you have a reason not to do so, store the users under their uid. By storing them under their uid, you can easily look up the data for a given user: ref.child('users').child(user.uid). If you stored the users under a generated key (such as a push id), you'd have to perform a query to find the same record.

    The examples you got from the documentation are using a different naming scheme. The reason for that is that both push IDs and UIDs would have led to more confusion than we wanted in the docs at that point. That's why we chose short, readable keys in those cases.

    0 讨论(0)
提交回复
热议问题