在Firebase数据库中构建朋友列表 [英] Structuring a friend list in a Firebase database

查看:156
本文介绍了在Firebase数据库中构建朋友列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找实现朋友系统Firebase数据库的最佳方法(至少是正确的方法),其中数据库中的每个用户都有自己的信息(他的姓名,个人资料图片,电子邮件等)以及一个朋友列表.

I am looking for the best way (or at least the right way) to implement a friend system Firebase database in which each user in the database has his own information (his name, profile picture, email, etc.) and a friend list.

问题是我想不出一种好的,有效的方法来将信息存储在数据库内部,例如,如果我以以下方式存储数据-

The problem is that I can't think of a good, efficient way to store the information inside the database, for example, if I store the data in the following way -

{
    "users": {
        "johnappleseed": {
            // name, profile picture URL, email, phone, etc...
            "friends": {
                "alice": true,
                "bob": true,
                "james": true,
                "johnappleseed2": true,
                // ...
            }
        },
        "johnappleseed2": {
            // ...
        }   
    }
}

,并且我希望该应用显示某个用户的朋友列表(其中显示了朋友的姓名,个人资料图片等).我仍然需要为每个执行服务器请求>列表中的朋友(而AFAIK执行大量服务器请求被认为是不正确的做法),以获取我想显示的超出其用户名的任何信息...此外,当用户更改其用户名时会发生什么?

and I want the app to show the list of friends of a certain user (which shows the friends' names, profile pictures, etc.) I would still need to perform a server request for each one of the friends in the list (while, AFAIK performing lots of server requests is considered a bad practice) to grab whatever information I want to display beyond their username... Also, what happens when a user changes their username?

任何人都可以提出更好的解决方案或更有意义的结构吗?

Can anyone suggest a better solution or a structure that would make more sense?

推荐答案

关于如何在Firebase上构建数据有很好的了解 https://firebase.google.com/docs/database/web/structure-数据

There is a good read about structuring data on firebase on https://firebase.google.com/docs/database/web/structure-data

在您的情况下,我会这样做

In your case I would do it something like this

  /users:
        21532761536: <-- user id
            name: henk
            birthdate: 14-05-2016
        27361726362:
            name: priscilla
            birthdate: 14-05-2016

    /friends:
        21532761536: <-- user id (henk)
            27361726362: true, <-- friends user id (priscilla)
            18237821732: true,
        27361726362:
            72163721637: true,

这篇关于在Firebase数据库中构建朋友列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆