I am new to the mongoDB aggregation pipeline and have a really basic question but could not find the answer anywhere. I would like to simply convert the following block:
"exclude" : [
{
"name" : "Accenture"
},
{
"name" : "Aon Consulting"
}
]
to:
"exclude" : [
"Accenture",
"Aon Consulting"
]
using the aggregation pipeline but I cannot seem to find how to do it even after going through the documentation on https://docs.mongodb.com/manual/reference/operator/aggregation/. Thanks for your help.
While @chridam's answer is correct, there is no need to use $map
.
Simple $addFields
/$project
would be sufficient:
db.collection.aggregate([
{
$addFields: {
exclude : '$exclude.name'
}
}
])