Você pode tentar corresponder à
category fornecida e createdAt -data usando $match , então agrupe e finalmente use $addToSet para obter todos os staffId exclusivos s:db.collection.aggregate([
{
$match: {
"category": "trend",
"createdAt": {$gte: new Date("2020-08-13T00:00:00Z"), $lt: ISODate("2020-08-14T00:00:00Z")}
}
},
{
"$group": {
"_id": null,
"staffIds": {
"$addToSet": "$staffId"
}
}
}
]);
Aqui está um exemplo no mongoplayground (teve que usar strings e regex para a data, pois ISODate não é suportado lá):https://mongoplayground.net/p/oGM7cfvCRQx