Do svého BuildConfig.groovy vložte toto
závislosti {
compile "org.mongodb:mongo-java-driver:2.10.1"
runtime "com.gmongo:gmongo:1.1"
}
A pak v sekci plugin
pluginy {
compile (":mongodb:1.1.0.GA"){
excludes 'mongo-java-driver', 'gmongo'
}
}
Tím se aktualizuje váš plugin mongodb, aby používal nejnovější ovladače java a gmongo.
Poté použijte agregační rámec. Příklad
DBObject match = new BasicDBObject('$match', new BasicDBObject("adPostId", 50) );
// build the $projection operation
DBObject fields = new BasicDBObject("adPostId", 1);
fields.put("shopperId", 1);
fields.put("_id", 0);
DBObject project = new BasicDBObject('$project', fields );
// Now the $group operation
DBObject groupFields = new BasicDBObject( "_id", '$karmaType');
groupFields.put("average", new BasicDBObject( '$sum', '$rating'));
DBObject group = new BasicDBObject('$group', groupFields);
// run aggregation
AggregationOutput output = db.karma.aggregate( match, project, group );
return [model:[avgkarma:output.getCommandResult()]]