简体   繁体   English

Mongodb,仅查找所有最新映射记录

[英]Mongodb, find all latest mapping records only

I have a mongodb collections with around 2000 millions data represents mobile devices. 我有一个mongodb集合,其中约有2000百万个数据代表移动设备。 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) 当我将其绑定到我的服务器时,我将生成一个设备ID,由于某些原因,它可能会注册多次,而对于一个设备,则可能会有多个deviceId(imei)

The generate id is the collection id so it is unique. 生成ID是集合ID,因此是唯一的。 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. 现在,我需要查询该集合中的所有设备映射,但是对于同一imei,我需要最新的设备ID。

In SQL I may write 在SQL中我可能会写

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? mongodb查询中有更快的方法吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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