I have this query in mongodb:
db.getCollection('users').aggregate([
{
$group: {
_id: "$type",
// items: { $push: "$_id.type" }
// items: { $addToSet: "$_id.type" }
}
},
{
$project: {
_id: 0,
type: "$_id",
}
}
]).toArray()
This will return a list like this:
[ {type: "AAA"}, {type: "BBB"}, {type: "CCC"} ]
But can I get something like this: ["AAA", "BBB", "CCC"]? Tried with $push and $addToSet but no result. Thank you for your time!
Later edit: You can find an example here: https://mongoplayground.net/p/-n0o5i6CnLq
_id: nullinstead of_id: "$type"["Male", "Female", "Rather not say", "Other"], an array, not an array of objects