Created
August 6, 2013 18:57
-
-
Save kurron/6167512 to your computer and use it in GitHub Desktop.
Example of a Spring Data MongoDB data structure that causes the aggregation framework in Spring Data MongoDB 1.3.0.RC1 to fail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Document | |
class DailyUserAggregate { | |
@Id | |
@Field( value = '_id' ) | |
String id | |
@Field( value = 'student' ) | |
Student student = new Student() | |
// other fields removed | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
when: 'report is run' | |
// the attributes to filter on | |
String INSTANCE = 'ONE' | |
String NODE = 'ONE' | |
String ORGANIZATION = 'ONE' | |
String SCHOOL_HOUSE = 'ONE' | |
String CLASS_CODE = 'ONE' | |
long START_DATE = 1 | |
long STOP_DATE = 30 | |
TypedAggregation<DailyUserAggregate> aggregation = newAggregation( DailyUserAggregate, match( where( 'instance' ).is( INSTANCE ).and( 'node' ).is( NODE ).and( 'organization' ).is( ORGANIZATION ).and( 'schoolHouses' ).is( SCHOOL_HOUSE ).and( 'student.classParticipation.code' ).is( CLASS_CODE ).and( 'dateCode' ).gte( START_DATE ).lte( STOP_DATE ) ), group( 'student.code' ).sum( 'student.totalLessonSessionCount' ).as( 'total-session-count' ) ) | |
AggregationResults<LearnerActivityReport> result = template.aggregate( aggregation, LearnerActivityReport ) | |
List<LearnerActivityReport> aggregate = result.getMappedResults() | |
// NOTICE the group( 'student.code' ) clause, this is causing the error because I'm trying to group on a property of a sub-object. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
org.springframework.data.mapping.PropertyReferenceException: No property code found for type org.kurron.domain.DailyUserAggregate | |
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75) | |
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327) | |
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307) | |
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:271) | |
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:245) | |
at org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext.getReference(TypeBasedAggregationOperationContext.java:81) | |
at org.springframework.data.mongodb.core.aggregation.GroupOperation.toDBObject(GroupOperation.java:284) | |
at org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:228) | |
at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1256) | |
at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1233) | |
at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1222) | |
at org.kurron.domain.DataPopulationLearningTest.execute learner activity report(DataPopulationLearningTest.groovy:158) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student { | |
@Field( value = 'student-id' ) | |
String code | |
// other fields removed | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment