I need to count how many users were created every day last week. I can get a total created user number of last week
var d = new Date();
d.setDate(d.getDate() - 7);
const data = await User.count({ "createdAt": { $gt: d } })
return res.status(200).json({ error: false, data: data })
sample data:
{
"_id": "612fa439gdb04331d6ea1e5d",
"name": "imran",
"createdAt": "2021-09-01T16:03:05.266Z",
},
{
"_id": "612fa439ddb44331d6ea1e5d",
"name": "Hossain",
"createdAt": "2021-08-31T16:03:05.266Z",
},
...........
expected output :
"user_count" : {
02-09-2021: 3,
01-09-2021: 5,
31-08-2021: 3,
30-08-2021: 5,
...
}
Use this API, I want to create a chart to show statistics. that API should provide which day, how many users were created. How can I do that?