2
我想爲1:1和羣聊活動創建聊天應用程序。NoSQL/MongoDB中的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
}
它會更好,以存儲用戶的「成員」數組訪問列表就像上面說的,或者這是解決與"chat_groups"
更好:
{ // user
"id": 1 // id of the user
"name": "Max" // name of the user
"chat_groups": [ "1", "2", ...] // ids of the groups, the user is a member of
}
模式的選擇應該是由應用程序的使用和大小決定。假設它是一個小型的演示應用程序,聊天組或用戶的所有信息都可以來自單個集合。當用戶看到他的儀表板並想要開始或加入與用戶或組。 – Avi