{
"_id": "5f6b45ad73cac785f0e7504c",
"user_id": "zzzz",
"survey_id": "40",
"questionList": [
{
"isDelete": 1,
"choices": [
{
"_id": "5f6b45ad73cac785f0e75068",
"name": "Choice1",
"value": "",
"score": 12,
"disqualifier": "true"
},
{
"_id": "5f6b45ad73cac785f0e75067",
"name": "choice2",
"value": "",
"score": 21,
"disqualifier": "true"
},
{
"_id": "5f6b45ad73cac785f0e75066",
"name": "choice3",
"value": "",
"score": 21,
"disqualifier": "false"
}
],
"_id": "5f6b45ad73cac785f0e75065",
"type": "mcq",
"name": "Multi Choice",
"value": "choice2",
"isMandatory": "true"
},
{
"isDelete": 0,
"choices": [
{
"_id": "5f6b45ad73cac785f0e75064",
"name": "option1",
"value": "",
"score": 12,
"disqualifier": "true"
},
{
"_id": "5f6b45ad73cac785f0e75063",
"name": "option2",
"value": "",
"score": 12,
"disqualifier": "false"
},
{
"_id": "5f6b45ad73cac785f0e75062",
"name": "option3",
"value": "",
"score": 33,
"disqualifier": "false"
}
],
"_id": "5f6b45ad73cac785f0e75061",
"type": "dropdown",
"name": "dropdown",
"value": "option2",
"isMandatory": "true"
}
I need to put a filer on survey_id and user_id along with that I need to select all object inside QUESTIONLIST where isDelete is 1. I literally tried soo many thinngs but seems nothing is working or Am i putting it wrong ?? here is what all I tried
await surveyfinal.find({$and:[{survey_id:req.body.survey_id},{user_id:req.body.user_id},{questionList:{$elemMatch:{isDelete:1}}}]})
await surveyfinal.find({user_id:req.body.user_id},{questionList:{$elemMatch:{isDelete:1}}} )
await surveyfinal.find({$and:[{user_id:req.body.user_id},{survey_id:req.body.survey_id},{"questionList.isDelete":1} ]})
If your goal is to only get the relevant array elements from the
questionList
-array for documents that match the givensurvey_id
anduser_id
, you can use the following aggregation to achieve this:Check out the example that I've created on mongoplayground.