So I\'ve got these documents in my people collection:
{
\"_id\" : ObjectId(\"595c0630939a8ae59053a9c3\"),
\"name\" : \"John Smith\",
You can wrap the $filter
expression inside $map
to map the output values.
db.people.aggregate([
{
"$project": {
"name": 1,
"age": 1,
"hobbies": {
"$map": {
"input": {
"$filter": {
"input": "$hobbies",
"as": "hobbyf",
"cond": "$$hobbyf.regular"
}
},
"as": "hobbym",
"in": {
"name": "$$hobbym.name",
"type": "$$hobbym.type"
}
}
}
}
}
])