我正在从事一个个人项目,以提高我在Node.js,Express,Socket.io和MongoDB方面的技能和经验。我似乎在制定数据库应如何用于此类应用程序方面遇到了障碍,我一直在考虑它,可以从需要一些时间的人那里获得一些帮助。我的应用程序允许用户输入用户名并选择房间标题。此后,他们将被加载到房间中,其他人可以加入该房间并实时聊天。我要保留数据,在断开连接时将其保存在每个房间,并在连接时重新填充。 每个房间都有与之关联的名称以及消息本身。每条消息都有一个发件人名称,时间戳和文本/内容。 但是,在实际构建模型以及如何组织集合方面,我感到困惑。谁能帮助我或让我走上这种应用程序的正确道路?
- 积分
0 - 话题
0 - 评论
3209 - 注册排名
2091
A simple approach is structuring the db with only one schema, the
Room
schema.When a user sends a message in a room, push to the messages array of that same room.
Then, in socket.io (node) you emit a socket (with the room id) and send the message, and in the client side, set the user to receive all sockets of that room.
房间架构: