MongoDB: best design for messaging app [duplicate] MongoDB: best design for messaging app [duplicate] mongoose mongoose

MongoDB: best design for messaging app [duplicate]


Based on your example data for the messaging app, what you could do is having two collections: Conversation and Messages. Where the relationship is one Conversation have many Messages.

Conversation:{ id: 123  participants: ['john', 'marry'],}Message:{ sender: 'john',   content: 'howdy',   time_created: new Date(),  converstationId: 123},{ sender: 'marry',   content: 'good u',   time_created: new Date(),  converstationId: 123 },

Creating a new document message would be better in this case, as you can then have two applications (1 for john and 1 for marry) without handling the possibility of the two of them updating the same document.They just happens to be sharing the same conversation session.

Also, if a conversation is a single document, you might end up with a very large document. (Document growth concern)

You can find out more about data modelling for this mongodb doc

http://docs.mongodb.org/manual/core/data-modeling-introduction/

Also see MongoDB: Socialite for examples/discussion for social network use case.

Hope it helps. Cheers.