3
我试过在网上搜索这个错误,但没有任何帮助。我正尝试在使用Java的mongodb中使用aggregate
函数。 RetailerZip
是我想将我的结果分组的字段。安装
groupFields = new BasicDBObject("_id", 0);
groupFields.put("count",new BasicDBObject("$sum",1));
groupFields.put("_id", "$RetailerZip");
group = new BasicDBObject("$group", groupFields);
sort = new BasicDBObject();
projectFields = new BasicDBObject("_id", 0);
projectFields.put("value", "$_id");
projectFields.put("ReviewValue","$count");
project = new BasicDBObject("$project", projectFields);
sort.put("ReviewValue",-1);
orderby=new BasicDBObject("$sort",sort);
limit=new BasicDBObject("$limit",5);
List<DBObject> pipeline = Arrays.asList(group, project, orderby, limit); //error occurs on this line.
AggregationOutput output = mongo.myReviews.aggregate(pipeline);
MongoDB的版本是:3.2.11
您可以加入你所得到的错误的详细信息?还有什么'组','项目'等是对象? – nullpointer
什么是'RetailerZip'没有在问题中提到。问题肯定需要改进。 – nullpointer