【问题标题】:firebase work with the user nick name or the user id?firebase 使用用户昵称或用户 ID?
【发布时间】:2020-05-06 22:42:26
【问题描述】:

我是 firebase 新手,我知道在 mysql 中我们有一个表 users 具有唯一 ID(例如:1、2...)。

如果我有一个表关注并且我想记录谁关注谁,我添加:

follow

1 3 // user_id 1 follows user_id 3
3 2
3 1

我想要最好的 firebase 实时数据库,我有一个 json 用户,也有唯一的密钥和用户名。我有 json 跟随:

关注:

CMypCAlwMXPeM8X07P0sKsO
 |
 --- randomkey
        |
        --- follow: UFPRK8GG4tMvCejEfqWiCE220Mv2

换句话说,用户CMypCAlwMXPeM8X07P0sKsO关注用户UFPRK8GG4tMvCejEfqWiCE220Mv2

在 firebase 中,我应该使用这个唯一的用户密钥(如 mysql)还是应该使用用户名?喜欢:

josh
 |
 ... randomkey
        |
        --- follow: marie

谢谢!

【问题讨论】:

    标签: firebase firebase-realtime-database database-design


    【解决方案1】:

    为了在 Firebase 实时数据库中为用户之间的追随者建模,我通常会得到三个顶级列表:

    users: {
      uid1: { ... },
      uid2: { ... },
      uid3: { ... }
    },
    followers: {
      uid1: {
        uid2: true
      },
      uid2: {
        uid3: true,
      },
      uid3: {
        uid1: true
      }
    },
    followees: {
      uid1: {
        uid3: true
      },
      uid2: {
        uid1: true,
      },
      uid3: {
        uid2: true
      }
    }
    

    因此,您实际上是将单个 follow 表拆分为两个顶级列表:一个用于关系的每个“方向”。

    另见:

    【讨论】:

      猜你喜欢
      • 2018-08-21
      • 1970-01-01
      • 2017-05-05
      • 2021-04-05
      • 1970-01-01
      • 2020-09-28
      • 2017-12-18
      • 1970-01-01
      • 2021-05-24
      相关资源
      最近更新 更多