c0m*_*ade 5 javascript notifications mongodb node.js
我正在努力在 Node.js 中实现类似于 Facebook 通知系统的通知系统。我见过一些使用 Socket.io 的实现,但我不知道它是否适合我的情况。我考虑的另一种方法是创建一个通知模型(我使用 MongoDB 作为存储),如下所示:
var Notification = new mongoose.Schema({
title: {type: String},
added: {type: Date},
accountId: {type: mongoose.Schema.ObjectId},
notificationType: {type: String},
isSeen: {type: Boolean}
});
Run Code Online (Sandbox Code Playgroud)
然后,我将在我的帐户架构中使用它:
var AccountSchema = new mongoose.Schema({
email: { type: String, unique: true },
password: { type: String },
name: {
first: { type: String },
last: { type: String },
full: {type: String}
},
notifications: [Notification]
});
Run Code Online (Sandbox Code Playgroud)
然后,我将根据操作向用户添加通知。但是,我不太确定这种方法是否有效。因此,我想知道哪种方法最适合这种情况:在线/离线通知。
提前致谢,
您确实应该研究用于实时通知的发布/订阅系统。
如果您遇到离线的订阅者,您可以存储在您的[通知]架构中。一旦用户再次连接,它就可以查询它们并确认它们已出现。
资源:
| 归档时间: |
|
| 查看次数: |
1664 次 |
| 最近记录: |