如何构建与firebase的友谊数据? [英] How to structure friendship data with firebase?

查看:129
本文介绍了如何构建与firebase的友谊数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是firebase的新手,我尝试构建我的数据来存储我的应用程序的用户之间的友谊。

我的数据结构如下:

  {users:{
user_1:{
name:John
},
user_2 :{
name:Jack
},
user_3:{
name:Georges
},
},
{friendships:{
user_1:{
user_2:{
name:Jack
},
user_3:{
name:Georges
},
user_3:{
user_1:{
name:John
},
user_2:{$ b $ name:Jack
}
}
}

我不知道我的数据结构是否可以,但是我不知道什么是最好的如果用户更改他的名字,如何更新友谊中的名字,我怎样才能轻松地更新友谊中的引用(每个节点的眉毛?)?

谢谢如果有人能帮助我理解正确的方式做到这一点。


$ b $

  {用户:{
user_1:{
名称:John
},
user_2: {
name:Jack
},
user_3:{
name:Georges
},
},
{friendhips:{
user_1:{
user_2:true,
user_3:true,
user_3:{
user_1:true,
user_2:true
}





$ b这与Dravidian所显示的相似,但取决于你有多少朋友,可能是一个更好的主意,不存储用户的朋友列表下的用户帐户的详细信息节点,因为如果你有1000以上的朋友,你将不得不下载1000孩子即使你只是想得到一个像他的名字一样的值。


I'm novice with firebase and I try to structure my data to store friendship between users of my app.

My data are structured like this :

    { users: {
        user_1: {
          name: John
        },
        user_2: {
          name: Jack
        },
       user_3: { 
          name: Georges
       },
   }, 
   { friendships : {
      user_1 : {
        user_2: {
            name: Jack
          },
        user_3: {
            name: Georges
      },
      user_3: {
        user_1: {
            name: John
        },
         user_2: {
            name: Jack
        }
    }
}

I don't know if my data structure is OK, but I wonder what is the best way to update a name in the friendships if a user changes his name, how can I easily update the reference in the friendships (brows each node ?) ?

Thank you if someone can help me to understand the right way to do that.

A.

解决方案

Your structure is almost good, but I would change the friendships node to this:

    { users: {
        user_1: {
          name: John
        },
        user_2: {
          name: Jack
        },
       user_3: { 
          name: Georges
       },
   }, 
   { friendships : {
      user_1 : {
        user_2: true,
        user_3: true,
      user_3: {
        user_1: true,
        user_2: true
    }
}

This is similar to what Dravidian showed, but depending on how many friends you have, it might be a better idea to not store the users friendslist under the users account details node because if you had 1000+ friends you would have to download 1000 children even if you just wanted to get a single value like his name.

这篇关于如何构建与firebase的友谊数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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