Indsæt dette i din BuildConfig.groovy
afhængigheder {
compile "org.mongodb:mongo-java-driver:2.10.1"
runtime "com.gmongo:gmongo:1.1"
}
Og så i plugin-sektionen
plugins {
compile (":mongodb:1.1.0.GA"){
excludes 'mongo-java-driver', 'gmongo'
}
}
Dette vil opdatere dit mongodb-plugin til at bruge de nyeste java-drivere og gmongo.
Brug derefter aggregeringsramme. Eksempel
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 );
returner [model:[avgkarma:output.getCommandResult()]]