我没有检查语法。另外我不知道您的查询是否有效,但这是我的尝试。
//unwind
DBObject unwind = new BasicDBObject("$unwind", "$scorearray");
// Now the $group operation
DBObject groupFields = new BasicDBObject("player", "$player");
groupFields.put("venue", "$scorearray.venue"));
groupFields.put("score", "$scorearray.score"));
DBObject group = new BasicDBObject("$group", new BasicDBObject("_id", groupFields));
//sort
DBObject sort = new BasicDBObject("$sort", new BasicDBObject("_id.score":1));
//secondgroup
DBObject secondGroupFields = new BasicDBObject("_id", "$_id.player")
secondGroupFields.put("maxScore", new BasicDBObject("$last":"$_id.score"));
secondGroupFields.put("venue", new BasicDBObject("$last":"$_id.venue"));
DBObject secondGroup = new BasicDBObject("$group", secondGroupFields);
// run aggregation
AggregationOutput output = playerScoreCollection.aggregate(unwind, group,sort,secondGroup);
Iterable<DBObject> result = output.results();
Iterator<DBObject> iterator = result.iterator();