I have a mongo db collection in which each document has two nested arrays (each document has an element that stores an array which stores documents that store another array) and I only want some fields of the deepest document. I have tried different types of projection elements but none of them worked. Right now I am trying the following:
let answered_exam = await exams_table.findOne(
{_id: new ObjectId(req.body.course_id)},
{projection: {
_id: 1,
"exams": {
"$map": {
"input": "$exams",
"in": {
"$this.exam_name": req.body.exam_name,
"students_exams": {
"$map": {
"input": "$$this.students_exams",
"in": { "student_email": req.body.student_email },
}},
},
}}
}
});
The format of an entry in the database is the following:
The block of attributes in the middle are the documents stored in the exams array
(each element is like this). The block from below is the format of the documents.
