[
{
"Empname": "Doug",
"Group": [
{
"Category": [
{
"Categoryid": 123,
"Categoryname": "science"
},
{
"Categoryid": 233,
"Categoryname": "Maths"
}
]
}
]
},
{
"Empname": "stark",
"Group": [
{
"Category": [
{
"Categoryid": 123,
"Categoryname": "science"
},
{
"Categoryid": 144,
"Categoryname": "language "
}
]
}
]
}
]
Here I want to insert two fields if it meets the following conditions
{
"Categoryid": 123,
"Categoryname": "science"
}
output should be like
[
{
"Empname": "Doug",
"Group": [
{
"Category": [
{
"Categoryid": 123,
"Categoryname": "science"
"CategoryLabel": "Hex",
"CategoryCode": "Hex-D",
},
{
"Categoryid": 233,
"Categoryname": "Maths"
}
]
}
]
},
{
"Empname": "stark",
"Group": [
{
"Category": [
{
"Categoryid": 123,
"Categoryname": "science",
"CategoryLabel": "Hex",
"CategoryCode": "Hex-D",
},
{
"Categoryid": 144,
"Categoryname": "language "
}
]
}
]
}
]
You need update with
arrayFiltersto meet the condition forCategoryarray.And with
multi: trueto update multiple documents.Sample Mongo Playground