I have a collection comprising of per minute data with fields : date(datatype-ISODate) and clicks(datatype-long). I need to group and sum clicks per day.
db.collectionname.aggregate([
{'$group':{'_id':{date:{$dayOfYear:'$date'}},clicks:{$sum:'$clicks'}}}])
this gives me day of year wise clicks, BUT i want the day in timestamp(for further use in other proccesses).
I have tried using "$substr" to group with only date part not time(works well), but even in that i cannot convert the date to timestamp.
db.collectionname.aggregate([
{'$group':{'_id':{date:{$substr:["$date",0,10]}},clicks:{$sum:'$clicks'}}}])
MySQL had a "UNIX_Timestamp()" function to convert date to timestamp , anything similar in MongoDB???
like ISODate(2016-03-30T00:00:00.000Z) to 1459276200000 (13 digits i.e. milliseconds) OR 2016-03-30 to 1459276200000 .
This is a different question, as here I am asking for a solution to convert the date-(2016-03-30) to timestamp. Other questions either have a pre-created field for this date or are using any ISODate not specified to 00.00.00.000 time.