A very simple design problem. Say I want to build Facebook Messenger. Let's say John and Marry are chatting, which is a better approach?
1) 1 document per conversation, messages
is an array of message object
{ participants: ['john', 'marry'],
messages: [
{ sender: 'john', content: 'howdy', time_created: new Date() },
{ sender: 'marry', content: 'good u', time_created: new Date() },
...
]
}
2) 1 document per message
{ participants: ['john', 'marry'], sender: 'john', message: 'howdy', time_created: new Date() } // document 1
{ participants: ['john', 'marry'], sender: 'marry', message: 'good u', time_created: new Date() } // document 2
....
Which approach has better performance in terms of inserting a new message (updating a conversation vs. creating a new document) ?
or are there any better approach (as in my 2nd approach, i'm not sure if it's a good design to specify the participants field in each document)?
Thanks!