Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mongodb中设计通知数据库模式?_Mongodb_Notifications - Fatal编程技术网

如何在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
      }
    
    优点:查询特定用户的通知会更快

    缺点:对于每个通知,“通知”收集将增加 当我在中重复相同的通知时 为其发送通知的多个用户收集通知 目的是

  • 2.我希望维护一个通知集合,对于每个通知文档,我维护该通知的用户数组和已阅读该通知的用户数组

    优点:通知集合大小可能更小

    缺点:通知文档的最大大小可能达到16 MB

    这是我唯一能想到的两件事,还有其他更好的方法吗?非常感谢您的帮助。

    这个怎么样

    {
        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,
    }