0

{ “_id” : 1 , “item” : “abc” , “price” : 10 , “quantity” : 2 , “date” : ISODate (“2014-03-01T08:00:00Z” ) }
{ “_id” : 2 , “item” : “jkl” , “price” : 20 , “quantity” : 1 , “date” : ISODate (“2014-03-01T09:00:00Z”) }
{ “_id” : 3, “项目” : “XYZ” ,“ 价格” : 5 , “量” : 10 , “日期” : ISODate (“2014-03-15T09:00:00Z” ) }
{ “_id” : 4 , “项目” : “xyz” , “price” : 5 , “quantity” : 20 , “date” : ISODate (“2014-04-04T11:21:39.736Z” ) }
{ “_id” : 5 , “项目” : “abc” , “price” : 10 , “quantity” : 10 , “date” : ISODate (“2014-04-04T21:23:13.331Z” ) }

如何按天分组,求出每天中quantity最大的那一列的price值。
下边查询的数据结构不相同,但是思路是一致的。
我在java处写了一个查询,现在能拿到的结果是按天查询出了每天最大的值,最大值那一列的其他值我不知道怎么让它显示,我该怎么做?

List opsRange = new ArrayList();
DBObject queryRange = new BasicDBObject(“created”, new
BasicDBObject(“$gte”,startDay).append(“$lt”, endDay));
queryRange.put(“terminalId”,tid);
DBObject matchWin = new BasicDBObject(“$match”, queryRange);
opsRange.add(matchWin);

DBObject proFieldsRange = new BasicDBObject(“cday”,new
BasicDBObject(“$dayOfMonth”,”$created”));
proFieldsRange.put(“ctime”, “$created”);
proFieldsRange.put(“level”, “$level”);
proFieldsRange.put(“rank”, “$rank”);
DBObject proRange = new BasicDBObject(“$project”, proFieldsRange );
opsRange.add(proRange);
DBObject groupRange = new BasicDBObject(“$group”, new BasicDBObject(“_id”,new
BasicDBObject(“cday”,”$cday”)).append(“maxt”,new BasicDBObject(“$max”,”$ctime”)));
opsRange.add(groupRange);

DBObject sortFieldsRange = new BasicDBObject(“_id.cday”, 1);
DBObject sortRange = new BasicDBObject(“$sort”, sortFieldsRange );
opsRange.add(sortRange);

AggregationOutput outputWin = template.getCollection(PK_RECORD).aggregate(opsRange);