zoukankan      html  css  js  c++  java
  • mongodb的查询操作

    1、条件匹配:MatchOperation

    MatchOperation matchOperation = Aggregation.match(new Criteria().where("area_code").is(areaCode));

    2、分组计数:GroupOperation + count

    GroupOperation groupSource_typeOperation = Aggregation.group("source_type", "satisfied_degree")
        .count().as("count").first("source_type").as("source_type");

    3、分组求和GroupOperation + sum

    GroupOperation groupDeptOperation = groupDeptOperation = Aggregation.group("dept_name")
        .sum("evaluate_quantity").as("evaluate_quantity").first("dept_name").as("dept_name");

    4、排序:SortOperation

    SortOperation sortOperation = Aggregation.sort(new Sort(Direction.DESC,"evaluate_quantity"));

    5、跳过:SkipOperation

    SkipOperation skipOperation = Aggregation.skip(10);

    6、限制查多少个:LimitOperation

    LimitOperation limitOperation = Aggregation.limit(10);

    7、执行查询

    注意,Operation的顺序一定要写对,不然查出来有差异,是按照add进list的顺序执行,直接写在入参中也是一样

    List<AggregationOperation> operations = new ArrayList<>();
    operations.add(matchDeptOperation);
    operations.add(groupDeptOperation);
    operations.add(skipOperation );
    operations.add(limitOperation);
    AggregationResults<Map> aggregate = mongoTemplate.aggregate(Aggregation.newAggregation(operations), EvaluateConstant.EVALUATE_COLLECTION, Map.class);
    

      

  • 相关阅读:
    react生命周期-渲染阶段
    react声明周期详解
    react子传父
    react 爷爷组件件传递给孙子组件
    react验证参数格式类型
    原生input上传视拼,参数形式 file: (binary)形式的
    L2-4 彩虹瓶 (25分)
    L2-3 深入虎穴 (25分)
    L2-1 链表去重 (25分)
    L1-1 帅到没朋友 (20分)
  • 原文地址:https://www.cnblogs.com/lansetuerqi/p/13933693.html
Copyright © 2011-2022 走看看