如何在mongodb中设计通知数据库模式?
我的应用程序是关于大学搜索的,将有两种用户,一种是搜索大学的最终用户,另一种是大学所有者 我为这两类用户维护一个通用的“用户”集合。其模式如下所示如何在mongodb中设计通知数据库模式?,mongodb,notifications,Mongodb,Notifications,我的应用程序是关于大学搜索的,将有两种用户,一种是搜索大学的最终用户,另一种是大学所有者 我为这两类用户维护一个通用的“用户”集合。其模式如下所示 { _id : ObjectId(), display_name: String, email: String, password_hash: String, type :Number } 现在,此应用程序的管理员希望向用户推送通知,此通知可能针对所有用户、特定用户、学院所有者或一组用户 通知文件由以下三部
{
_id : ObjectId(),
display_name: String,
email: String,
password_hash: String,
type :Number
}
现在,此应用程序的管理员希望向用户推送通知,此通知可能针对所有用户、特定用户、学院所有者或一组用户
通知文件由以下三部分组成:
{
_id : ObjectId(),
notification_message: String,
date: Date
}
现在,我想做的是点击一个api,它为我提供特定用户的所有通知,以及每个通知的标志字段,它表示通知是已读还是未读
现在,我的数据库设计应该如何
我想到了两个选择
{
_id : ObjectId(),
notification_message: String,
date: Date,
to_user_id : ObjectId(),
mark_as_read: Boolean
}
优点:查询特定用户的通知会更快
缺点:对于每个通知,“通知”收集将增加
当我在中重复相同的通知时
为其发送通知的多个用户收集通知
目的是{
sender: Object, // user object
receiver: [ String ] //array of user _ids
message: String, // any description of the notification message
read_by: [{ readerId: String, read_at: Date }],
created_at: Date,
}