node.js - mongodb messaging schema design -


i'm working on nodejs & mongodb project i'm implement instant messaging feature website between users. need object structure stored in our mongodb database.

requirements are:

  • any user of website should able send message user
  • messages should grouped in threads similar forum, each thread created when user sends message user via presentation page
  • sender and/or recipient should able reply thread
  • even if recipient/sender removes entire thread (or specific message in thread), other user should still see messages (if he/she not delete them)
  • each user have inbox , sent, trash common mail box

this have far

messages:[{     '_id'   : '502c21e3833ea71307001d56',     'from'  :  {                     '_id': '503fdbfa294f6db74de649ea',                     'name': 'kumar'     },     'to'    : {             '_id'   : '5061e2a61ac427f716000378',             'name'  : 'elan'     },     'subject'   : 'sit amet consectetur',     'message'   : 'lorem ipsum dolor sit amet, consectetur adipiscing elit',     'sent'      : '2012-09-26t18:04:26.656z',     'last_reply': '2012-09-26t18:04:26.656z',     'reply'     : [                 {                     'content': 'dolor sit amet consectetur adipiscing elit.',                     'to': {                         '_id': '503fdbfa294f6db74de649ea',                         'name': 'kumar'                     },                     'from'  :  {                         '_id': '5061e2a61ac427f716000378',                         'name': 'elan'                     },                     'date': '2012-09-26t18:04:26.656z'                 },                 {                     'content': 'consectetur adipiscing elit. ',                     'to': {                         '_id': '5061e2a61ac427f716000378',                         'name': 'elan'                     },                     'from'  :  {                         '_id': '503fdbfa294f6db74de649ea',                         'name': 'kumar'                     },                     'date': '2012-09-26t18:04:26.656z'                 }             ]  }] 

messages_user_mapping

 messages_user_mapping : [{         '_id'   : '502c21e3833ea71307001222',         'msg_id' : '502c21e3833ea71307001d56',         'user' : {                 '_id': '503fdbfa294f6db74de649ea',                 'name': 'kumar'             },         'sent' : '1',         'inbox': '0',         'trash': '0',         'soft_delete':{             'msg_id' : '502c21e3833ea71307001d56',             'from'  : 'inbox'         }     },     {         '_id'   : '502c21e3833ea71307001222',         'msg_id' : '502c21e3833ea71307001d56',         'user' : {                 '_id': '5061e2a61ac427f716000378',                 'name': 'elan'             },         'sent' : '0',         'inbox': '1',         'trash': '0',         'soft_delete':{             'msg_id' : '',             'from'  : ''         }     }     ] 

i looking better schema structure.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -