I want to convert this array of object
[{ category:"AAA" },{ category:"BBB" },{ category: "CCC" }]
Into this
["AAA","BBB","CCC"] . I don't want to filter or use any array function in the backend but from the mongoDB itself.
I want to convert this array of object
[{ category:"AAA" },{ category:"BBB" },{ category: "CCC" }]
Into this
["AAA","BBB","CCC"] . I don't want to filter or use any array function in the backend but from the mongoDB itself.
$map maps the object keys in the array to an array of the key values. Then use $addFields to transfrom the output
arr = [{ category:"AAA" },{ category:"BBB" },{ category: "CCC" }];
db.collection.aggregate([
{
"$addFields": {
"exclude": {
"$map": {
"input": "$arr",
"as": "el",
"in": "$$el.category"
}
}
}
}
])