Puede intentar hacer coincidir la category
dada y createdAt
-fecha usando $match
, luego agrupe y finalmente use $addToSet
para obtener todos los staffId
únicos 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"
}
}
}
]);
Aquí hay un ejemplo en mongoplayground (tuvo que usar cadenas y expresiones regulares para la fecha porque ISODate no es compatible allí):https://mongoplayground.net/p/oGM7cfvCRQx