命令失败,错误16410:'FieldPath字段名称不能以'$'开头。'

我试过在网上搜索这个错误,但没有任何帮助。我正尝试在使用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

回答:

你把 “_id” 两次在$小组赛阶段。 试图取代这一

groupFields = new BasicDBObject("_id", 0); 

groupFields.put("count",new BasicDBObject("$sum",1));

groupFields.put("_id", "$RetailerZip");

通过

groupFields = new BasicDBObject("_id", "$RetailerZip"); 

groupFields.put("count",new BasicDBObject("$sum",1));

以上是 命令失败,错误16410:'FieldPath字段名称不能以'$'开头。' 的全部内容, 来源链接: utcz.com/qa/259963.html

回到顶部