I have the object below in MongoDB and my back end is using nodeJS. to retrieve the data from DB. the "_id" field is provided in the API body.
questions = [
{
"_id": "idq1"
"questiontext": "some question",
"author": "auth2",
"Answers": []
},
{
"_id": "idq2"
"questiontext": "some question",
"author": "auth1",
"Answers": [
{
"author": "auth1",
"comments" [...],
"status" : "1"
},
{
"author": "auth2",
"comments" [...],
"status" : "0"
},
{
"author": "auth3",
"comments" [...],
"status" : "1"
}
]
}
]
Expected result:
I want to get an object where the status is equal to "1" my expected result is given below :
result = {
"_id": "idq2"
"questiontext": "some question",
"author": "auth1",
"Answers": [
{
"author": "auth1",
"comments" [...],
"status" : "1"
},
{
"author": "auth3",
"comments" [...],
"status" : "1"
}
]
}
Understanding the aggregation, it always return an array, so an array should be fine too.