charlie rose
charlie rose

Reputation: 21

How do you group by isodate year, month, day?

How to group by isodate, preferably by year, month, day?

Upvotes: 2

Views: 2587

Answers (1)

gokultp
gokultp

Reputation: 165

I am adding a simple group query, will count the number of entries for each date. Refer the following documentation for more date operators. https://docs.mongodb.com/v3.4/reference/operator/aggregation-date/

db.getCollection('callmodels').aggregate([
    {$group: {_id: {day: {$dayOfMonth :"$date" }, month: {$month :"$date" }, year: {$year :"$date" }}, count: {$sum:1}}}
])

Upvotes: 5

Related Questions