I have a mongodb collections with around 2000 millions data represents mobile devices. I will generate a device id when it rigister to my server, for some reasons, it may register multiple times, some there may be more than one deviceId for one device(imei)
The generate id is the collection id so it is unique. the collection is like
id | imei | createTime
Now I need to query all device mappings from this collection, but for the same imei, I need the latest device id.
In SQL I may write
select id, imei from table join ( select max(createTime), imei from table group by imei) as t2 on(imei, createTime).
Is there a faster way in mongodb query?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.