Di BuildConfig.groovy Anda, masukkan ini
dependensi {
compile "org.mongodb:mongo-java-driver:2.10.1"
runtime "com.gmongo:gmongo:1.1"
}
Dan kemudian di bagian plugin
plugin
compile (":mongodb:1.1.0.GA"){
excludes 'mongo-java-driver', 'gmongo'
}
}
Ini akan memperbarui plugin mongodb Anda untuk menggunakan driver java dan gmongo terbaru.
Kemudian gunakan kerangka kerja agregasi. Contoh
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 );
kembalikan [model:[avgkarma:output.getCommandResult()]]