首页 > 数据库 >MongoDB查询

MongoDB查询

时间:2022-11-23 16:12:09浏览次数:57  
标签:ad MongoDB Aggregation 查询 Criteria where id 分页

        // 返回的字段
        ProjectionOperation projectionOperation = Aggregation.project("user_isp_tag", "ad_title", "ad_id", "push_url", "clicksum");
 
        // 日期条件
        Criteria operator = Criteria.where("ad_id").ne("").andOperator(
                Criteria.where("click_time").gte(startDate),
                Criteria.where("click_time").lt(endDate)
        );
        MatchOperation matchOperation = Aggregation.match(operator);
 
        // 分组操作,并对每个广告的总条数进行统计
        GroupOperation groupOperation = Aggregation.group("ad_id", "ad_title").sum("clicknum").as("clicksum");
        // 分页操作,控制分页从哪开始
        SkipOperation skipOperation = Aggregation.skip(pageQuery.getPageQuery_start());
        // 分页操作,控制分页取得记录数
        LimitOperation limitOperation = Aggregation.limit(pageQuery.getPageQuery_pageSize());
        // 组合条件
        Aggregation aggregation = Aggregation.newAggregation(projectionOperation, matchOperation, groupOperation, skipOperation, limitOperation);
        // 执行操作
        AggregationResults<AddspAnalyse> aggregationResults = this.mongoTemplate.aggregate(aggregation, "collectionName", AddspAnalyse.class);

 

标签:ad,MongoDB,Aggregation,查询,Criteria,where,id,分页
From: https://www.cnblogs.com/raorao1994/p/16918598.html

相关文章