duration = 7; // active user 7 days
dateTo = new Date();
dateTo.setHours(0, 0, 0);
dateFrom = new Date();
dateFrom.setDate(dateTo.getDate() - duration);
dateFrom.setHours(0, 0, 0);
db.getCollection("users").aggregate( // collection users
[
{
$match: { // filter by "created"
created: { $gte: dateFrom, $lt: dateTo }
}
},
$match: { // filter by "created"
created: { $gte: dateFrom, $lt: dateTo }
}
},
$group: {
_id: "id", // group by "id"
uniqId: { $addToSet: "$id" }, // get uniq "id" only
},
]
);
ไม่มีความคิดเห็น:
แสดงความคิดเห็น