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:
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")
}
]
}