简体   繁体   中英

Mongodb, find all latest mapping records only

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?

要在mongo中完成分组,您可以使用较旧的分组依据聚合框架

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM