How would you model an email app (like gmail) in MongoDB? Would you model a Conversation
? Inbox
/ OutBox
? or mail
?
Thanks
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With