I have two collections students and teachers in the mongodb database. Below is an example structure of a conversation between a student and a teacher. In the student and teacher object, I have an array of messages containing objects that are messages, and receiver and sender containing the id of the person sending and receiving the message. I am asking for advice on what function to create to download common messages for the sender and receiver and display them either on the sender's or the receiving side, depending on who sent. On the left side of the message if it was sent by the student, on the right side if it was sent by the teacher. Anyone have material explaining how to do this??
Students
{
"_id": { "$oid": "600333" },
"name": "MMMMMM",
"surname": "xxxxx",
"email": "mar@gmail.com",
"role": "student",
"messages": [
{
"contentInfo": {
"viewed": false,
"msg": "22222222ghjk",
"createdAt": { "$date": { "$numberLong": "" } }
},
"_id": { "$oid": "" },
"receiver": { "$oid": "5fea6e09" }
},
{
"contentInfo": {
"viewed": false,
"msg": "heloooo",
"createdAt": { "$date": { "$numberLong": "" } }
},
"_id": { "$oid": "" },
"receiver": { "$oid": "5fea6e09" }
},
{
"contentInfo": {
"viewed": false,
"msg": "dfdfdf",
"createdAt": { "$date": { "$numberLong": "" } }
},
"_id": { "$oid": "" },
"receiver": { "$oid": "600333" }
}
]
}
Teachers
{
"_id": { "$oid": "5fea6e09" },
"isActiveTutor": false,
"youtubeUrlId": "",
"name": "rrrr",
"surname": "rrrrr",
"email": "u@gmail.com",
"initials": "",
"role": "tutor",
"createdAt": { "$date": "" },
"updatedAt": { "$date": { "$numberLong": "" } },
"messages": [
{
"contentInfo": {
"viewed": false,
"msg": "22222222ghjk"
"createdAt": { "$date": "" }
},
"_id": { "$oid": "" },
"sender": { "$oid": "600333" }
},
{
"contentInfo": {
"viewed": false,
"msg": "heloooo",
"createdAt": { "$date": { "$numberLong": "" } }
},
"_id": { "$oid": "" },
"sender": { "$oid": "600333" }
},
{
"contentInfo": {
"viewed": false,
"msg": "dfdfdf",
"createdAt": { "$date": { "$numberLong": "" } }
},
"_id": { "$oid": "" },
"sender": { "$oid": "5fea6e09" }
}
]
}
from Retrieving messages shared by the sender and receiver - chat mongodb, express, react
No comments:
Post a Comment