버전 : Spring Data MongoDB 2.7.9
예외 메세지
Method threw 'java.lang.IllegalArgumentException' exception.
Cannot evaluate org.springframework.data.mongodb.core.aggregation.Aggregation.toString()
해당 예외는 아래의 코드에서 발생했다
GroupOperation groupByRoomId = group(roomId).push(content).as(content);
LimitOperation limit = new LimitOperation(pageable.getPageSize());
SortOperation sort = Aggregation.sort(Sort.by(Sort.Order.desc(createdAt)));
MatchOperation matchStage = Aggregation.match(
Criteria.where(RoomColumn.PARTICIPATIONS.getWord())
.all(userId)
);
ProjectionOperation projection =
Aggregation.project()
.and(roomId).as(roomId)
.and(content).as(content)
.and(createdAt).as(createdAt);
Aggregation aggregation = Aggregation.newAggregation(
projection, groupByRoomId, matchStage, sort, limit
);
List<ChatRoomResDto> messages = mongoTemplate.aggregate(
aggregation,
"chat_room",
ChatRoomResDto.class)
.getMappedResults();
간단한 예외였는데
ProjectionOperation에서 적은 것과
mongoTemplate.aggregate 안에서 적은 Collection의 이름이 달라서 생긴 문제.
해당 Collection은 chat_room이 아니라 message 였어야 함!!
해당 컬렉션에 있는 필드와 Aggregation 에서 가져올 필드들이 맞는지 확인해보자!
'Spring > error' 카테고리의 다른 글
Java 17에서 LocalDateTime 이슈 (3) | 2024.12.26 |
---|---|
[에러] Failed to evaluate Jacson - InvalidDefinitionException: Cannot handle managed/back reference (0) | 2022.05.19 |
Spring Boot - Execution failed for task ':bootRun'. (0) | 2022.05.16 |
Spring boot - 멀티 모듈에서 gradle dependencies 오류(해결 안 됨) (0) | 2022.04.26 |