I'm looking for a solution to filter a mongodb aggregation using the $in operator.
It looks for an id string inside an array of strings using an aggregate query, quite simple in concept:
db.post.aggregate({ $project: {
present: { $in: ["569d659d1b5075f9020041be", "$comments" ] },
name: "$name" }
})
This query gives me the projection I need, in the shape:
{
"_id" : ObjectId("545d6a491b5075ec020041d8"),
"present" : false,
"name" : "Clarity Of Vision"
}
How can I filter that projection in order to get, for example the projected elements in which present is true
?
Is there a way to do it in the same aggregate query?