在春天,它看起來像這樣
String collection="collection";
Aggregation agg = newAggregation(
unwind("data.mi")
,sort(DESC,"data.mi.failures")
,group("data.mi.name")
.sum("data.mi.failures").as("sum_total_of_failures")
.first("uid").as("uid")
);
AggregationResults<Type> aggregate = mongoOperations.aggregate(agg, collection, objectClass);
隨着這些進口假設
import com.mongodb.BasicDBObject;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import static org.springframework.data.domain.Sort.Direction.*;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
謝謝,這是有益的... :) – vmr
好 - 如果你快樂,你能接受答案嗎? :-) –
我是................ :) – vmr