MongoDB Structure for message app

后端 未结 4 747
误落风尘
误落风尘 2021-01-30 07:18

I am breaking my mind up thinking about a good document structure for handling a message app.

I basically need three (or four) types of objects:

  1. The user (
4条回答
  •  感动是毒
    2021-01-30 07:59

    I see that this question is old, but for anyone interested, a similar question was asked and one answer looks viable https://stackoverflow.com/a/30830429/132610

    Conversation : {
     id: 123,
     members: [ user_id1, user_id2 ]
    }
    Message { conversationId: 123, author: user_2, body: 'Hi what's up' }
    Message { conversationId: 123, author: user_1, body: 'Whanna ask some question on stackoverflow' }
    

    Update #1

    1) Scalability: MongoDB scales well with very large collection. Billions of messages per collection. There is a technique called sharding that can allow you to split larger collection to multiple nodes.

    2) Reading. Since MongoDB has indexing mechanisms, reads are comparable to any fine-tuned database engine. So reading will not be an issue. Especially, when a conversation(group|room) has fewer participants, for example two people messaging each other.

提交回复
热议问题