I have the object below. "questions" is the document name and each question has a nested array of type answers property where some answers has a propoerty call status.
questions = [
{
"_id": "idq1"
"author" :"auth1"
"Answers": []
},
{
"_id": "idq2"
"author" :"auth2"
"Answers": [
{
"author": "auth1",
"comments" [...],
"status" : "1"
},
{
"author": "auth2",
"comments" [...],
},
{
"author": "auth3",
"comments" [...],
"status" : "0"
}
]
}
]
I need to update all the nested Answers.status = "1" , where the Answers length > 0 and the nested element "status" does not exist. so the result would be :
questions = [
{
"_id": "idq1"
"author" :"auth1"
"Answers": []
},
{
"_id": "idq2"
"author" :"auth2"
"Answers": [
{
"author": "auth1",
"comments" [...],
"status" : "1"
},
{
"author": "auth2",
"comments" [...],
"status" : "1"
},
{
"author": "auth3",
"comments" [...],
"status" : "0"
}
]
}
]