0

I have have a mongo collection that keeps state records for devices. 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.

Here's the constraints:

  • Pass in a Set<'String'> name_ids, regular field within mongo collection not the _id or found within the _id
  • get only the latest record for each device with matching name_id
  • return List<'DeviceStateData'> (No duplicates should be found with the same name_id)

example of collection object:

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

Thanks

Xavier Guihot
  • 54,987
  • 21
  • 291
  • 190
Sam
  • 51
  • 6

1 Answers1

1

You should look on Distinct function.

Here you can find details with Spring.

Community
  • 1
  • 1
iMysak
  • 2,170
  • 1
  • 22
  • 35