Vous pouvez envelopper le $filter
expression dans $map
pour mapper les valeurs de sortie.
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"
}
}
}
}
}
])