I have a collection of data stored in mongodb, but it stores them with a date time format, but I want to count all records that occur on each day. The sql I am trying to reproduce is:
select count(*)
, mydate
from mytable
group by mydate
Currently, if i do
o1 := bson.M{
$match : bson.M {
"name" : result.Id,
},
}
o2 := bson.M {
"$project" : bson.M {
"_id" : 1,
"mydate" : 1,
},
}
o3 := bson.M {
"$group" : bson.M {
"_id" : "$mydate",
"total" : bson.M { "$sum" : 1 },
},
}
operators := []bson.M{o1, o2, o3)
pipe := dbObject.Pipe(operators)
results := []bson.M{]
err := pipe.All(&results)
This returns 1 single record for each date/time row. I would like to strip the time and get all records by the date only.