【发布时间】:2017-04-11 02:32:31
【问题描述】:
我已尝试在互联网上搜索有关此错误的信息,但没有任何帮助。我正在尝试使用 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
【问题讨论】:
-
您能否添加您遇到的错误的详细信息?还有
group、project等是什么对象? -
问题中没有提到
RetailerZip是什么。问题当然需要改进。