Guest User

Untitled

a guest
Mar 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. {
  2. _id: "241324123412",
  3. name_id: "flyingMan",
  4. powerState:"ON",
  5. timeStamp: ISODate('')
  6. }
  7.  
  8. import static org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation;
  9. import static org.springframework.data.mongodb.core.query.Criteria.where;
  10.  
  11. Aggregation aggregation = newAggregation(
  12. match(findCriteria),
  13. sort(new Sort(Sort.Direction.DESC, "name_id", "timeStamp")),
  14. group("name_id").first("$$ROOT").as("latest"));
  15.  
  16. List<DeviceStateData> deviceData = mongoTemplate.aggregate(aggregation, DeviceStateData.class, DeviceStateData.class).getMappedResults();
Add Comment
Please, Sign In to add comment