相关疑难解决方法(0)

MongoDB:消息应用程序的最佳设计

一个非常简单的设计问题.说我想建立Facebook Messenger.让我们说John和Marry在聊天,这是一种更好的方法吗?

1)每个会话1个文档,messages是一个消息对象数组

{ participants: ['john', 'marry'], 
  messages: [ 
      { sender: 'john', content: 'howdy', time_created: new Date() },
      { sender: 'marry', content: 'good u', time_created: new Date() },
      ...
  ]
}
Run Code Online (Sandbox Code Playgroud)

2)每封邮件1个文件

{ participants: ['john', 'marry'], sender: 'john', message: 'howdy', time_created: new Date() } // document 1
{ participants: ['john', 'marry'], sender: 'marry', message: 'good u', time_created: new Date() } // document 2
.... 
Run Code Online (Sandbox Code Playgroud)

在插入新消息(更新会话与创建新文档)方面,哪种方法具有更好的性能?

或者是否有更好的方法(如我的第二种方法,我不确定在每个文档中指定参与者字段是否是一个好的设计)?

谢谢!

database mongoose mongodb node.js express

16
推荐指数
1
解决办法
8996
查看次数

NoSQL / MongoDB 中的 1:1 和群聊模式

我想为 1:1 和群聊活动创建一个聊天应用程序。

我为这两种情况创建了一个架构:

{ // group 
    "id": 1 // id of the group
    "name": "Chat Group" // name of group; if there are more than 2 members
    "members": [ "member1", "member2", ...] // ids of the group chat members; only they have access to the JSON document
    "chatlog": [ "timestamp1": ["member1", "message1"], "timestamp2": ["member2", "message2"], ...] // who sent which message in chronological order
}
Run Code Online (Sandbox Code Playgroud)

如上所示,将用户的访问列表存储在“成员”数组中会"chat_groups"更好,还是这个解决方案更好:

{ // user 
    "id": 1 // id of the user
    "name": …
Run Code Online (Sandbox Code Playgroud)

mongodb nosql

5
推荐指数
1
解决办法
2920
查看次数

标签 统计

mongodb ×2

database ×1

express ×1

mongoose ×1

node.js ×1

nosql ×1