Reputation: 336
I have a json array structured like this:
{
"properties": [{
"name": "ok",
"value": 1
},
{
"name": "ok_aswell",
"value": 1
},
{
"name": "ok_aswell",
"value": 2
},
{
"name": "get_rid",
"value": 2
}
]
}
I want my query to return everything except the "get_rid" record:
{
"properties": [{
"name": "ok",
"value": 1
},
{
"name": "ok_aswell",
"value": 1
},
{
"name": "ok_aswell",
"value": 2
}
]
}
I tried the suggestions from here: Conditionally include a field (_id or other) in mongodb project aggregation? , however they didn't seem to work.
Upvotes: 1
Views: 34
Reputation: 1274
Try $filter in projection aggregate
{$project:{
properties:{
$filter: {
input: "$properties",
as: "item",
cond: {$ne: ["$$item.name","get_rid"]}
}
}
}}
Upvotes: 2