MongoDB Structure for message app

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

    this is my suggestion

    {
    "_id" : ObjectId("5a9e9581a2147c0c0f00002e"),
    "id_members1" : "5a9e9581a2147c0c0f02345t",
    "id_members2" : "5a9e9581a2147c0c0f02134g",
    "name" : [ 
        "Omar", 
        "Mohamed"
    ],
    "messages" : [ 
        {
            "author" : "Omar",
            "body" : "salam 3likom",
            "create_at" : ISODate("2018-03-07T09:04:04.000Z")
        }, 
        {
            "author" : "Mohamed",
            "body" : "Wa3likom salam",
            "create_at" : ISODate("2018-03-07T09:04:04.000Z")
        }, 
        {
            "author" : "Mohamed",
            "body" : "wach teshak",
            "create_at" : ISODate("2018-03-07T09:04:04.000Z")
        }, 
        {
            "author" : [ 
                "Omar", 
                "Mohamed"
            ],
            "body" : "test msg",
            "create_at" : ISODate("2018-03-25T15:30:05.000Z")
        }
    ],
    "comments" : [ 
        null, 
        {
            "author" : [ 
                "Omar", 
                "Mohamed"
            ],
            "body" : "test msg",
            "create_at" : ISODate("2018-03-25T15:28:11.000Z")
        }, 
        {
            "author" : [ 
                "Omar", 
                "Mohamed"
            ],
            "body" : "test msg",
            "create_at" : ISODate("2018-03-25T15:28:31.000Z")
        }
    ]
    

    }

提交回复
热议问题