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);
    

      

  • 相关阅读:
    c++ 对象大小内存占用分析
    运维(SA)修仙 之路 II
    分享好文章-Ansible 进阶技巧
    java JWT 登录认证
    ftp:500 OOPS: chroot
    centos 磁盘清理
    redis分析命令
    linux查找内容
    vim使用
    查看进程端口
  • 原文地址:https://www.cnblogs.com/lansetuerqi/p/13933693.html
Copyright © 2011-2022 走看看