What I'm trying to do should be relatively simple. My document is called "clicks", and looks like this:
{
"_id":"5dcc53f30666eacfdb9d9f59"
, "productID":"5dcc4c47a0d861ec6a0b432b"
, "userIP":"XX.XX.XX"
}
I just want to get back the number of clicks per day, using _id and (I assume) GetTimestamp() to figure out the date:
[
{
"date":"2019-11-01"
, "clicks":"125"
}
,{
"date":"2019-11-02"
, "clicks":"153"
}]
I thought that I could do something like this, but it's not working:
db.clicks.aggregate([
{"$group" : {_id: ObjectId(_id).getTimeStamp(), count:{$sum:1}}}
])
All the examples I'm seeing (eg: group by dates in mongodb ) have an element in the document containing a date element-- how do I do this JUST with the _id?