Я хочу агрегировать по группам, затем сортировать и ограничивать.Вот мой код:
if(m!=null){
db = m.getDB("FMdb");
DBCollection collection = db.getCollection("user_artists");
DBObject group = new BasicDBObject("$group", new BasicDBObject("_id", "$artistID").append("total", new BasicDBObject("$sum", "$weight")));
DBObject sort = new BasicDBObject("$sort", new BasicDBObject("total", -1));
DBObject limit = new BasicDBObject("$limit", 1);
List<DBObject> pipeline = Arrays.asList(group,sort,limit);
AggregationOutput output = collection.aggregate(pipeline);
for (DBObject d : output.results()){System.out.println(d);}
}
Вот сообщение об ошибке от bash:
Exception in thread "main" com.mongodb.MongoCommandException: Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument' on server 127.0.0.1:27017. The full response is { "ok" : 0.0, "errmsg" : "The 'cursor' option is required, except for aggregate with the explain argument", "code" : 9, "codeName" : "FailedToParse" }