我正在实现一个类似于 Facebook 通知系统的 Node.js 通知系统。我看过一些使用 Socket.io 实现的例子,但我不确定它是否适用于我的情况。我想另一种方法是创建一个 Notification 模型(我使用 MongoDB 作为存储),类似这样:
var Notification = new mongoose.Schema({
title: {type: String},
added: {type: Date},
accountId: {type: mongoose.Schema.ObjectId},
notificationType: {type: String},
isSeen: {type: Boolean}
});
然后,我将在我的账户架构中使用这个:
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]
});
接下来,我将根据用户的行为对通知进行一些添加。然而,我不确定这种方法是否会奏效。因此,我想知道在这种情况下哪种方法最好:在线/离线通知。
提前感谢。