问题描述
假设我们有一个名为student
的集合,我需要找出:
- 特定学校中所有学生的人数。
- 在校学生的总数。
@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 (将#修改为@)