0

Trying to build an aggregate query that would allow me to get the count of users that were created each day for a set range of dates. I have a users collection with data that looks in part like

{ 
"_id" : ObjectId("value"), 
"updatedAt" : ISODate("2017-10-08T21:13:18.260+0000"), 
"createdAt" : ISODate("2017-10-08T21:12:19.099+0000"), 
}

Currently using a simple match query of

db.users.aggregate(

// Pipeline
[
    // Stage 1
    {
        $match: {
         "createdAt": { $gte: ISODate("2017-10-08"), $lte: ISODate("2017-10-10") } 
        }
    },

I'm unsure of how to group the results of the match so it's separated by whole days. If I do a simple group

$group: {
_id: "$createdAt"
}

It returns grouping thats in minutes and hours of the same day

Ideally output would look something like

{
"count": 100,
"date": "2017-10-08"
},
{
"count": 120,
"date": "2017-10-09"
}
{
"count": 150,
"date": "2017-10-10"
}
Meir Snyder
  • 789
  • 1
  • 6
  • 16

0 Answers0