1.查询子文档列表最后一条
sql
db.units_statistics_hourly.find({
"unitNumber": "F8N9P141"
}, {
"runDuration": {
$slice: [ - 1, 1]
},
"runCounts": {
$slice: [ - 1, 1]
}
});
java
public UnitStatisticsHourly getTotalPerformance(String unitNumber) {
Criteria criteria = Criteria.where("unitNumber").is(unitNumber);
Query query = Query.query(criteria);
query.fields().slice("runDuration", -1, 1)
.slice("runCounts", -1, 1);
UnitStatisticsHourly totalPerformance = mongo
.findOne(query, UnitStatisticsHourly.class, COLLECTION_PERFORMANCE_HOURLY_NAME);
return totalPerformance;
}
|