MongoDB Structure for message app

后端 未结 4 657
误落风尘
误落风尘 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:39

    Please find my suggestion:

        Person : {
            person_id: '123',
            last_login: 12.06.2008,
            online: true
        }
    
    Conversation : {
     conversation_id: append the greater person_id to the lower person_id, // person_1_id =123 and person_2_id =124 then its 123124
    
    messages: [ 
            { message_id: 1, 
              message_text : 'Hi what's up',
              sender_id : 123,
              receiver_id: 124,
              timestamp : 12344567891
            },
            { message_id: 2, 
              message_text : 'fine',
              sender_id : 124,
              receiver_id: 123,
              timestamp : 12344567891
            }
           ]
    }
    

提交回复
热议问题