title: How to design a notification database schema in mongodb?
body: <p>My application is about college search, there will be two kind of users, one the end users who search for colleges and other the college owners.</p>
  
  <p>I am maintaining a common 'users' collection for both the kinds of users. Its schema looks like below</p>
  
  <pre><code>{
      _id : ObjectId(),
      display_name: String,
      email: String,
      password_hash: String,
      type :Number
  
  }
  </code></pre>
  
  <p>Now an admin of this application wants to push a notification to the users, this notification may be for all the users or for a particular user or for the owners of the colleges or for a group of users.</p>
  
  <p>A notification document consists of three things like below,</p>
  
  <pre><code>{
    _id : ObjectId(),
    notification_message: String,
    date: Date
  }
  </code></pre>
  
  <p>Now what I want to do is to hit an api which gives me all the notifications of a particular user, along with a flag field for each notification which represents whether the notification is read or unread.</p>
  
  <p>Now for this how should be my database design?</p>
  
  <p>I thought of two options,</p>
  
  <ol>
  <li><p>I want to maintain a notification collection and repeat the notification document for every intended user of the notification also I would maintain a field in this document as 'mark as read', the document will look like this</p>
  
  <pre><code> {
     _id : ObjectId(),
    notification_message: String,
    date: Date,
    to_user_id : ObjectId(),
    mark_as_read: Boolean
    }
  </code></pre>
  
  <p><strong>Pros</strong>:Querying for the notifications of a particular user will be faster</p>
  
  <p><strong>Cons</strong>:For each notification 'notification' collection will increase
            drastically as I am repeating the same notification in 
            notification collection for many users for whom the notification
           is intended to.</p></li>
  </ol>
  
  <p>2.I want to maintain a notification collection and for each notification document I maintain an array of users for that notification and an array of users who have read this notification</p>
  
  <p><strong>Pros:</strong> Notification collection size may be less</p>
  
  <p><strong>Cons:</strong> Notification document may hit the maximum size of 16 MB</p>
  
  <p>These are only two things I could think of, is there any other better way to do this? Your help will be very much appreciated.</p>