db.profileInterest.aggregate([
{ $project: { _id: 1, fromProfile: 1, toProfile: 1, contactNoViewed:1, shortListed: 1, count: {$size: '$interestStatus'}, threeFavorites: { $slice: [ "$interestStatus", -1 ] }} },
{$match: {"threeFavorites.id": {$ne: 100}}}
]).pretty();
答案 0 :(得分:1)
保存List<DBObject>
中的聚合输出,如下所示:
AggregationOutput aggregationOutput = mongoTemplate
.getCollection("collection_name")
.aggregate(aggregationList);
List<DBObject> dbObjects = (List<DBObject>) aggregationOutput.results();
在java类型中转换List<DBObject>
,如下所示:
for(DBObject dbObject : dbObjects) {
mongoTemplate.getConverter().read(klass, dbObject);
}