我想使用单个聚合查询在Spring数据mongodb中的多个匹配/位置条件的基础上找到多个计数

问题描述

假设我们有一个名为student的集合,我需要找出:

  1. 特定学校中所有学生的人数。
  2. 在校学生的总数。
@Document
class Student{
    @Id
    private String Id;
    // all others are @Field annotated
    
    private String name;
    private boolean isPresent;
    private String lastName;
    private String roolNo;
    private String schoolId;
}

我写了这个:

Aggregation aggregation = 
    newAggregation(match(Criteria.where("schoolId")
                                 .is("1")
                                 .and("isPresent")
                                 .is(true)),group().count()
                          .as("totalStudentCount")); 
AggregationResults<Student> count =
    mongoTemplate.aggregate(aggregation,Student.class,Student.class);

但是以上内容将使课程返回的仅是在校学生,而不是在校学生,因此我们可以为其添加其他条件吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...