I have records stored in mongodb this way
{
"resource": [
{
"user": "usr-0001",
"deviceid": 101,
"fixtime": 1461485045000
},
{
"user": "usr-0001",
"deviceid": 102,
"fixtime": 1461485068000
},
{
"user": "usr-0002",
"deviceid": 201,
"fixtime": 1461485098000
},
{
"user": "usr-0002",
"deviceid": 202,
"fixtime": 1461485128000
},
{
"user": "usr-0002",
"deviceid": 202,
"fixtime": 1461485141000
}
]
}
How can I get only the last inserted records for each device belonging to a particular user? If the user has 5 devices it should return only the last inserted (5) records (based on fixtime) for that user. The fixtime shown is unix time.
Something like what’s described here: http://stackoverflow.com/questions/16368162/retrieve-the-last-inserted-row-from-each-user-in-database