• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

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

java 来源:trin 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


===========解决方案如下:

你把 “_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)); 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)