org.springframework.data.mongodb.core.MongoTemplate.group()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(1.8k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中org.springframework.data.mongodb.core.MongoTemplate.group()方法的一些代码示例,展示了MongoTemplate.group()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MongoTemplate.group()方法的具体详情如下:
包路径:org.springframework.data.mongodb.core.MongoTemplate
类名称:MongoTemplate
方法名:group

MongoTemplate.group介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-data-mongodb

public <T> GroupByResults<T> group(String inputCollectionName, GroupBy groupBy, Class<T> entityClass) {
  return group(null, inputCollectionName, groupBy, entityClass);
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

public <T> GroupByResults<T> group(String inputCollectionName, GroupBy groupBy, Class<T> entityClass) {
  return group(null, inputCollectionName, groupBy, entityClass);
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

@Override
public List<ObservationObjectCount> getMostObservedObjects(ObservationObjectType objectType, Date fromDate, int limit) {
  Criteria criteria = Criteria.where(QUERY_PARAM_OBJECT_TYPE).is(objectType.name());
  if (fromDate != null) {
    criteria.andOperator(Criteria.where(QUERY_PARAM_CREATION_TIMESTAMP).gte(fromDate));
  }
  GroupBy groupBy = GroupBy.key(QUERY_PARAM_OBJECT_ID).initialDocument("{ count: 0 }").reduceFunction("function(doc, prev) { prev.count += 1 }");
  GroupByResults<ObservationObjectCount> groupByResults = mongoTemplate.group(criteria, mongoCollectionName, groupBy, ObservationObjectCount.class);
  List<ObservationObjectCount> result = new ArrayList<ObservationObjectCount>();
  for (Iterator<ObservationObjectCount> iterator = groupByResults.iterator(); iterator.hasNext();) {
    ObservationObjectCount objectCount = (ObservationObjectCount) iterator.next();
    result.add(objectCount);
  }
  Collections.sort(result);
  Collections.reverse(result);
  result = result.subList(0, limit);
  return result;
}

相关文章