I'm currently working on a nodejs & mongodb project where I'm to implement a Instant Messaging feature to the website between users. What I need help with is the object structure to be stored in our mongodb database.
Requirements are:
This is what I have so 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 am looking for better schema structure.