my collection has structure like this:
"listQuestion": [
{
"answer_type": 0,
"listShortAnswer": [],
"listQuestionChildren": [],
"quiz_type": 1,
"listPairing": [],
"listAnswer": [
{
"is_true": false,
"answer_content": " \\[x=-2\\] ",
"answer_url_image": "",
"answer_url_mp3": "",
"answer_id": 136948
},
{
"is_true": true,
"answer_content": " \\[x=-1\\] ",
"answer_url_image": "",
"answer_url_mp3": "",
"answer_id": 136950
},
I have an aggregation variable called $$isShowAnswer, if it is true, the is_true will be show, or else it won't
here is my projection with $cond
$project: {
'listAnswer.is_true': {
$cond: { if: { $eq: ["$$isShowAnswer", false] }, then: "$$REMOVE", else: 1}
},
},
but the result is like below
{
"answer_content": " \\[x=-2\\] ",
"answer_url_image": "",
"answer_url_mp3": "",
"answer_id": 136948,
"is_true": 1
},
{
"answer_content": " \\[x=-1\\] ",
"answer_url_image": "",
"answer_url_mp3": "",
"answer_id": 136950,
"is_true": 1
},
how can I remove "is_true" field if the condition is correct and do nothing if it's wrong?