简体   繁体   English

Mongo DB /无重复

[英]Mongo DB / No duplicates

I have have a mongo collection that keeps state records for devices. 我有一个mongo集合,用于保存设备的状态记录。 Thus, there could be multiple records per device. 因此,每个设备可能有多个记录。 What I would like to do is create a query through the mongoTemplate that gets the latest record for each device. 我想做的是通过mongoTemplate创建一个查询,该查询获取每个设备的最新记录。

Here's the constraints: 这里是约束:

  • Pass in a Set<'String'> name_ids, regular field within mongo collection not the _id or found within the _id 传递Set <'String'> name_ids,在mongo集合中的常规字段不是_id或在_id中找到
  • get only the latest record for each device with matching name_id 仅获取每个具有匹配name_id的设备的最新记录
  • return List<'DeviceStateData'> (No duplicates should be found with the same name_id) 返回List <'DeviceStateData'>(不应找到具有相同name_id的重复项)

example of collection object: 收集对象的示例:

{
  _id: "241324123412",
  name_id: "flyingMan",
  powerState:"ON",
  timeStamp: ISODate('')
}

Thanks 谢谢

You should look on Distinct function. 您应该看一下Distinct函数。

Here you can find details with Spring. 在这里,您可以找到有关Spring的详细信息。

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

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