Firebase 3 - 如何为个人/群组消息传递构建数据库:可能是多对多?

时间:2016-11-17 01:26:19

标签: angular firebase firebase-realtime-database

我对Firebase数据建模很陌生,我一直在尝试找出最有效和可扩展的方法来为想要向其他用户发送消息的用户创建数据存储,或者甚至成为每个人都在其中的群组的一部分该组正在向该单个组发送消息。

用例1:用户第一次向另一个用户发送消息(没有创建对话),并且仅限于这两个用户。

用例2:超过2个用户向对话发送消息。可以随时添加或删除用户。类似地,Facebook的消息传递。

我相信这将是一个多对多关系,在阅读Firebase documentation关于如何构建数据库(甚至尝试根据他们的示例建模我的数据)后,我已经出现了以下内容:

{
      users: {
        mcbean: {
          conversations: {
             convo1: true,
             convo2: true,
          }
        },
        orion: {
          conversations: {
            convo1: true,
            convo2: true,
          }
        },
        leguy: {
          conversations: {
            convo2: true,
          }
        }
      },
      conversations: {
        convo1: {
          type: "individual"
          last_message: "this was the last thing said in the convo",
          created_at: 1463315112,
          users: {
            mcbean: true,
            orion: true
          }
        },
        convo2: {
          type: "group"
          last_message: "this was the also the last thing said in the convo",
          created_at: 1463315112,
          users: {
            mcbean: true,
            orion: true,
            leguy: true
          }
        }
      },
      conversation_messages: {
        convo1: {
          m1: {
            photo_url: "https://cdn.madeupthing.com/profile-img.png"
            body: "Let's get this party started",
            created_at: 1463315112
          },
          m2: { ... },
          m3: { ... }
        }
      }
    }

这是我要找的吗?我正在使用Ionic 2(和扩展名为Angular 2)构建我的应用程序,我只是想确保这是最容易阅读/更新的。想法?

1 个答案:

答案 0 :(得分:0)

你的架构看起来很好,因为我理解它(也是一个菜鸟)。下面是支持此架构的文档供其他人点击(我相信你看到了)。如果它运作良好,请告诉我们。

https://firebase.google.com/docs/database/ios/structure-data#fanout