MongoDB复杂聚合查询与java中MongoTemplate的api对应

news/2024/10/21 5:33:10/

MongoDB聚合json脚本

db.getCollection("202303_refund").aggregate([{"$match": {"courseType": "常规班课","teacherRefundReasonCheck": true,"teacherId": {"$in": [7544]},"createTime": "2023-09-08"}
}, {"$group": {"_id": {"subject": "$subject","schoolAreaId": "$schoolAreaId","grade": "$grade","classId": "$classId","isRefund": "$isRefund","teacherId": "$teacherId"},"subject": {"$first": "$subject"},"schoolAreaId": {"$first": "$schoolAreaId"},"grade": {"$first": "$grade"},"classId": {"$first": "$classId"},"isRefund": {"$first": "$isRefund"},"teacherId": {"$first": "$teacherId"},"refundCount": {"$sum": 1}}
}, {"$project": {"_id": 0,"subject": 1,"schoolAreaId": 1,"grade": 1,"classId": 1,"refundCount": 1,"teacherId": 1,"isRefund": {"$ifNull": ["$isRefund", 0]}}
}])

MongoTemplate的API

Aggregation aggregation = Aggregation.newAggregation(Aggregation.match(new Criteria("courseType").is("常规班课").and("teacherRefundReasonCheck").is(true).and("teacherId").in(Sets.newHashSet(7544)).and("createTime").is("2023-09-08")),Aggregation.group("subject","schoolAreaId","grade","classId","isRefund","teacherId").first("subject").as("subject").first("schoolAreaId").as("schoolAreaId").first("grade").as("grade").first("classId").as("classId").first("isRefund").as("isRefund").first("teacherId").as("teacherId").count().as("refundCount"),Aggregation.project("subject","schoolAreaId","grade","classId","refundCount","teacherId","isRefund"));Iterator<RefundResult> iterator = mongoTemplate.aggregate(aggregation, "202303_refund",RefundResult.class).iterator();

http://www.ppmy.cn/news/1097820.html

相关文章

Voxel R-CNN:基于体素的高性能 3D 目标检测

论文地址&#xff1a;https://arxiv.org/abs/2012.15712 论文代码&#xff1a;https://github.com/djiajunustc/Voxel-R-CNN 论文背景 基于点的方法具有较高的检测精度&#xff0c;但基于点的方法通常效率较低&#xff0c;因为对于点集抽象来说&#xff0c;使用点表示来搜索最…

HTTP 和 HTTPS

一.HTTP HTTP&#xff08;Hypertext Transfer Protocol&#xff09;是一种用于在网络上传输超文本&#xff08;Hypertext&#xff09;和其他资源的应用层协议。HTTP是Web中最常用的协议之一&#xff0c;它使得浏览器可以请求和显示网页&#xff0c;也允许服务器传送网页内容和其…

聚观早报|华为Mate 60 Pro支持面容支付;特斯拉重回底特律车展

【聚观365】9月8日消息 华为Mate 60 Pro已支持面容支付 特斯拉将重回底特律车展 iPhone在美国有1.67亿用户 韩国半导体8月份出口85.6亿美元 比亚迪元PLUS冠军版将于9月15日上市 华为Mate 60 Pro已支持面容支付 毫无预热的华为Mate 60 Pro突然在华为商城首批开售&#xf…

如何使用adb command来设置cpu频率和核数

透過ADB Shell設定CPU開核與freq的command與用法如下: # Disable PPM echo 0 > /proc/ppm/enabled # Enable PPM (Default) echo 1 > /proc/ppm/enabled echo 0 > /proc/ppm/enabled Fixed # Core for each cluster echo X Y > /proc/ppm/policy/ut_fix_core_num …

推断统计|显著性水平|无偏抽样

推断统计则是研究如何利用样本数据来推断总体特征的统计学方法&#xff0c;其内容包括参数估计和假设检验两大类。其中&#xff0c;参数估计是利用样本信息推断总体特征&#xff1b;假设检验是利用样本信息判断对总体的假设是否成立。 推断统计学是统计学的一个重要分支&#…

自然语言处理学习笔记(九)———— OVV Recall Rate与 IV Recall Rate

目录 1.OVV Recall Rate 2. IV Recall Rate 1.OVV Recall Rate OOV指的是“未登录词”&#xff08;Out Of Vocabulary&#xff09;&#xff0c;或者俗称的“新词”&#xff0c;也即词典未收录的词汇。如何准确切分00V&#xff0c;乃至识别其语义&#xff0c;是整个NLP领域的核…

微服务模式:服务发现模式

由于微服务应用的动态性&#xff0c;很难调用具有固定 IP 地址的服务。这就是服务发现的概念出现的背景。服务发现有助于客户端了解服务实例的位置。在这种情况下&#xff0c;服务发现组件将充当服务注册表。 服务注册表是一个包含服务实例位置的集中式服务器/数据库。在微服务…

如何利用ProcessOn 做资产管理流程图

资产管理 是一家公司最重要的管理活动。好的资产管理可以让资源最优化利用&#xff0c;实现资产价值的最大化。可以帮助组织管理和降低风险。同时当需要决策的时候&#xff0c;对资产数据进行分析和评估&#xff0c;也可以帮助做出更明智的决策&#xff0c;如优化资产配置、更新…