I have data in the form
{userid: 123,
actiontype: 'loggedin',
timestamp: date-time}
I want to run a query which will group the data for unique combinations of userid and actiontype, and return the document with the latest timestamp value.
Any ideas how I can do this?
At present i am thinking of doing a find and then throwing the returned values into arrays (python and pymongo) and then do the operations there. However, i feel that it will be much more elegant/efficient to do this directly on the mongodb.
You can do it with Mongo group function. The following code shows how you can do it.