These are chat archives for Automattic/mongoose

Feb 2018
Daouda Fofana
Feb 26 2018 04:12

Hi guys
I do have a question concerning database model
Reference or embedded
Hi guys, I am building a kind of messaging applica​tion and actually I encounter a problem with how to make the database model.

Like, suppose Jo and Harry are chatting, obviously they have messages:

  1. Document per conversation (embedded)

{ participants: ['jo', 'harry'],
messages: [
{ sender: 'jo', content: 'howdy', time_created: new Date() },
{ sender: 'harry', content: 'good u', time_created: new Date() },
​_id: f3redsvrbefgvreqvd

  1. Document per message (reference)
    { _id: 123
    participants: ['jo', 'harry'],

{ sender: 'jo',
content: 'howdy',
time_created: new Date(),
converstationId: 123
{ sender: 'harry',
content: 'good u',
time_created: new Date(),
converstationId: 123
More embedding is often recommended but the problem is the size of a document which cannot exceeded 16 megabytes. It may be possible that if people use the app frequently it may exceeded.
The second approach is about response time for query suppose a conversation has been referenced more than 10.000 times, it will take some time to fetch all of this if I want to load them all and suppose then 10 conversations referenced like this .
Can you suggest me with explanation please.
Thanks for reading