mongo-db-example updated

This commit is contained in:
stvort
2023-09-18 22:43:17 +04:00
parent c0735f92b2
commit 1e68829c12
3 changed files with 4 additions and 3 deletions
@@ -1,2 +1,3 @@
1695056720328:m
1695056755656:exit
1695062261073:m
@@ -24,7 +24,7 @@ import static org.springframework.data.mongodb.core.query.Criteria.where;
public class StudentRepositoryCustomImpl implements StudentRepositoryCustom {
@Data
private class ArraySizeProjection {
private static class ArraySizeProjection {
private int size;
}
@@ -43,7 +43,6 @@ public class StudentRepositoryCustomImpl implements StudentRepositoryCustom {
, project().and("experience._id").as("_id").and("experience.name").as("name")
);
Document rawResults = mongoTemplate.aggregate(aggregation, Student.class, Knowledge.class).getRawResults();
return mongoTemplate.aggregate(aggregation, Student.class, Knowledge.class).getMappedResults();
}
@@ -21,7 +21,8 @@ public class TeacherRepositoryCustomImpl implements TeacherRepositoryCustom {
val aggregation = newAggregation(
match(Criteria.where("id").is(teacherId))
, unwind("experience")
, project().andExclude("_id").and("experience.id").as("_id").and("experience.name").as("name")
, project().andExclude("_id").and("experience.id").as("_id")
.and("experience.name").as("name")
);
return mongoTemplate.aggregate(aggregation, Teacher.class, Knowledge.class).getMappedResults();
}