How to find, update, delete a document in an embedded array using aggregation pipeline?

{
classId: 1
numberOfStudents: 4
Students:
[
{
studentId: 1001,
studentName: ‘foo’
},
{
studentId: 1002,
studentName: ‘bar’
},
{
studentId: null
studentName: null
},
{
studentId: null
studentName: null
},
{
studentId: null
studentName: null
},
{
studentId: null
studentName: null
},

}

How can I locate and update specific student by name and update it?
How can I delete first student record which matches certain name?

Hi @Abhishek_Kumar_Singh,

Why do you need it with aggregation pipeline and not a regular update? Are you using pipeline update type?

For updates you have arrayFilters to specify criteria for the updated object.

Why do you have multiple place holders with null? Why not just to use $push when a new student is added to a class?

Thanks
Pavel

I need to conditional update, and I believe conditional update support is not available in regular update right?
I see your point regarding placeholder, totally agreed.

It is supported, look at the link I posted

I am sorry by conditional update I meant $cond operator like functionality. I couldn’t find anything in this regard.

Hi @Abhishek_Kumar_Singh,

Can you describe the initial document and the updated one?

Im afraid im still missing the point.

Thanks