I want to make the same operation like this to return an array of strings:
model.find().distinct("some_field")
How it's possible to take the same result using aggregation function?
I want to make the same operation like this to return an array of strings:
model.find().distinct("some_field")
How it's possible to take the same result using aggregation function?
You can use below code to get all unique some_field using aggregate:
model.aggregate([
{
$group:{
_id: null,
some_field: { $addToSet: '$some_field' }
}
}
]);