Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you model an Email app in MongoDB?

How would you model an email app (like gmail) in MongoDB? Would you model a Conversation? Inbox / OutBox? or mail?

Thanks

like image 458
Henry Avatar asked Apr 05 '11 22:04

Henry


1 Answers

Gmail use concept of labels (like tags on stackoverflow). That mean that inbox, send mail, starred, etc normal Email object, just marked with specified label. So, there are only Email and Labels.

You can see it using search in gmail like label:inbox or label:Starred.

I'd like to suggest a fairly simple design like this:

Email
    {
      _id
      Title,
      Body,
      Status {read, unread},
      Labels { name, type(system, custom) },
      Replies {...},
      ..
    }

Labels
    {
      _id,
      name,
      settings {
              ShowInLabelsList (show, hide, showIfUnread),
              ShowInMessageList (show, hide),
              ..
               }
     }

For sure i've missed something, but i guess it's okay to start from above schema and add more features in future if neeed.

Update:

For the 'Conversation View' i guess all replies show go to the nested collection Replies (i've update my schema). Logic is following:

Once you have received a new message you need check if email with same name already exists (for sure need to Remove 'Re', etc..) also need to check that user that has sent email in list of recipients. If above conditions is true then just add new email to nested collection of Replies otherwise add to collection of emails.

like image 106
Andrew Orsich Avatar answered Sep 20 '22 11:09

Andrew Orsich