java.lang.IllegalArgumentException: Invalid reference '_id.ubsId'!

Spring JIRA | Rubi Hali | 2 years ago
  1. 0

    Hi I am using spring data mongodb 1.4.1.RELEASE version. query which i am trying with mongo shell is running fine db.users.aggregate({ $match : { '_id' : "8105846361" } },{$unwind:'$searchProfile.verticalProfiles'},{$group:{_id:'$searchProfile.verticalProfiles'}},{$sort:{'_id.ubsId':-1}}) { "result" : [ { "_id" : { "vertical" : "jobs", "ubsId" : "10208", "userSearchProfiles" : [ { "searchProfiles" : { "Location" : "Mombasa", "FunctionalArea" : "HR", "Experience" : "2", "Designation" : "Admin" }, "ulqId" : "10201" } ] } }, { "_id" : { "vertical" : "realestate", "ubsId" : "10206", "userSearchProfiles" : [ { "searchProfiles" : { "PropertyType" : "Independent House", "NoOfBedrooms" : "5", "PropertyFor" : "Buy", "Location" : "Mombasa" }, "ulqId" : "10200" } ] } } ], "ok" : 1 } But when i try the same with spring data mongo db using aggregation template Aggregation agg = Aggregation.newAggregation( Aggregation.match(Criteria.where("_id").is(msisdn)), Aggregation.unwind("searchProfile.verticalProfiles"), Aggregation.group("searchProfile.verticalProfiles"), Aggregation.sort(Sort.Direction.DESC,"_id.ubsId") ); it throws an error java.lang.IllegalArgumentException: Invalid reference '_id.ubsId'! at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:78) at org.springframework.data.mongodb.core.aggregation.SortOperation.toDBObject(SortOperation.java:70) at org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:247) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1322) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1311) at in.verse.user.profile.repositories.impl.UserRepositoryImpl.sortByKey(UserRepositoryImpl.java:112) at in.verse.user.profile.service.test.UserRepositoryImplTest.save(UserRepositoryImplTest.java:69) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Please help me if somebody has faced the same issue and solved it

    Spring JIRA | 2 years ago | Rubi Hali
    java.lang.IllegalArgumentException: Invalid reference '_id.ubsId'!
  2. 0

    Hi I am using spring data mongodb 1.4.1.RELEASE version. query which i am trying with mongo shell is running fine db.users.aggregate({ $match : { '_id' : "8105846361" } },{$unwind:'$searchProfile.verticalProfiles'},{$group:{_id:'$searchProfile.verticalProfiles'}},{$sort:{'_id.ubsId':-1}}) { "result" : [ { "_id" : { "vertical" : "jobs", "ubsId" : "10208", "userSearchProfiles" : [ { "searchProfiles" : { "Location" : "Mombasa", "FunctionalArea" : "HR", "Experience" : "2", "Designation" : "Admin" }, "ulqId" : "10201" } ] } }, { "_id" : { "vertical" : "realestate", "ubsId" : "10206", "userSearchProfiles" : [ { "searchProfiles" : { "PropertyType" : "Independent House", "NoOfBedrooms" : "5", "PropertyFor" : "Buy", "Location" : "Mombasa" }, "ulqId" : "10200" } ] } } ], "ok" : 1 } But when i try the same with spring data mongo db using aggregation template Aggregation agg = Aggregation.newAggregation( Aggregation.match(Criteria.where("_id").is(msisdn)), Aggregation.unwind("searchProfile.verticalProfiles"), Aggregation.group("searchProfile.verticalProfiles"), Aggregation.sort(Sort.Direction.DESC,"_id.ubsId") ); it throws an error java.lang.IllegalArgumentException: Invalid reference '_id.ubsId'! at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:78) at org.springframework.data.mongodb.core.aggregation.SortOperation.toDBObject(SortOperation.java:70) at org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:247) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1322) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1311) at in.verse.user.profile.repositories.impl.UserRepositoryImpl.sortByKey(UserRepositoryImpl.java:112) at in.verse.user.profile.service.test.UserRepositoryImplTest.save(UserRepositoryImplTest.java:69) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Please help me if somebody has faced the same issue and solved it

    Spring JIRA | 2 years ago | Rubi Hali
    java.lang.IllegalArgumentException: Invalid reference '_id.ubsId'!
  3. 0

    Ternary operator not supported in aggregation projection expressions?

    Stack Overflow | 2 years ago | Rob Worsnop
    java.lang.IllegalArgumentException: Unsupported Element: org.springframework.data.mongodb.core.spel.ExpressionNode@76c423f9 Type: class org.springframework.data.mongodb.core.spel.ExpressionNode You probably have a syntax error in your SpEL expression!
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    I have the following mongodb document: {code:javascript} { "cmsParameterId":1, "examples":null, "rules":[ { "ruleType":"CODED", "values":[ "abc", "efg" ] }, { "ruleType":"SEQUENCE", "sequence":[ { "value":"a", "type":"CONSTANT" }, { "value":"2", "type":"PARAMETER" } ] } ] } {code} I use the following query in mongo shell which works fine. {code:javascript} db.domainknowledge.aggregate([ { $match: {cmsParameterId: { $in: [1] } } }, { $project: { cmsParameterId : 1 , rules : 1 }}, { $unwind: "$rules" }, { $group: { _id: { cmsParameterId: "$cmsParameterId", ruleType: "$rules.ruleType"}, total: { $sum: 1 } } } ]); {code} using spring-data I have written the following code to produce the same result but it ends up in an Exception: {code:java} Aggregation agg = newAggregation(match(Criteria.where("cmsParameterId").in(1)), project("cmsParameterId", "rules"), unwind("rules"), group("cmsParameterId", "rules.ruleType").count().as("totol")); AggregationResults<Summary> aggregate = mongoTemplate.aggregate(agg, "domainknowledge", Summary.class); {code} Here is the stacktrace of exception: {code:xml} java.lang.IllegalArgumentException: Invalid reference 'rules.ruleType'! at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:78) at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:62) at org.springframework.data.mongodb.core.aggregation.GroupOperation.toDBObject(GroupOperation.java:300) at org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:247) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1405) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1346) at com.etilize.automation.dke.core.domainknowledge.report.DomainKnowledgeReportServiceImpl.generateCategoryWiseReport(DomainKnowledgeReportServiceImpl.java:57) {code}

    Spring JIRA | 3 years ago | Faisal Feroz
    java.lang.IllegalArgumentException: Invalid reference 'rules.ruleType'!
  6. 0

    Mongo Shell working command. {code} db.person.aggregate( { $unwind: "$descriptors.carDescriptor.entries" }, {$project: {make: "$descriptors.carDescriptor.entries.make", model: "$descriptors.carDescriptor.entries.model", firstName:"$firstName", lastName: "$lastName"}}, {$group: {_id: "$make"}} ) {code} Equivalent Spring Data representation {code} Aggregation agg = Aggregation.newAggregation( unwind("descriptors.carDescriptor.entries"), project() .and("descriptors.carDescriptor.entries.make").as("make") .and("descriptors.carDescriptor.entries.model").as("model") .and("firstName").as("firstName") .and("lastName").as("lastName"), group("make") ); {code} While the Mongo Shell query work fine, Spring MongoTemplate form does not and returns the following error {noformat} java.lang.IllegalArgumentException: Invalid reference 'make'! at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:92) at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:62) at org.springframework.data.mongodb.core.aggregation.GroupOperation.toDBObject(GroupOperation.java:292) at org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:247) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1323) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1306) at com.example.samples.MongoTemplateTest.testAggregation(MongoTemplateTest.java:82) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) {noformat} Pojo classes {code} // getter, setter omitted @Document public class Person { @Id private String id; private String firstName; private String lastName; private Descriptors descriptors; } public class Descriptors { private CarDescriptor carDescriptor; } public class CarDescriptor { private List<Entry> entries; class Entry { private String make; private String model; private int year; } } {code} To confirm if "make" is being returned remove the group("make") operator from the fluent api and the output shows that the make is indeed being returned. Any pointers / work arounds ? Thank you, Adil Fulara

    Spring JIRA | 3 years ago | Adil Fulara
    java.lang.IllegalArgumentException: Invalid reference 'make'!

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Invalid reference '_id.ubsId'!

      at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference()
    2. Spring Data MongoDB - Core
      MongoTemplate.aggregate
      1. org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:78)
      2. org.springframework.data.mongodb.core.aggregation.SortOperation.toDBObject(SortOperation.java:70)
      3. org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:247)
      4. org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1322)
      5. org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1311)
      5 frames
    3. in.verse.user
      UserRepositoryImplTest.save
      1. in.verse.user.profile.repositories.impl.UserRepositoryImpl.sortByKey(UserRepositoryImpl.java:112)
      2. in.verse.user.profile.service.test.UserRepositoryImplTest.save(UserRepositoryImplTest.java:69)
      2 frames
    4. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:606)
      4 frames
    5. JUnit
      InvokeMethod.evaluate
      1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      4. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      4 frames
    6. Spring TestContext
      SpringJUnit4ClassRunner.runChild
      1. org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
      2. org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
      3. org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      4. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      5. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
      5 frames
    7. JUnit
      ParentRunner$2.evaluate
      1. org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      2. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      3. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      4. org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      5. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      5 frames
    8. Spring TestContext
      RunAfterTestClassCallbacks.evaluate
      1. org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      2. org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      2 frames
    9. JUnit
      ParentRunner.run
      1. org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      1 frame
    10. Spring TestContext
      SpringJUnit4ClassRunner.run
      1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      1 frame
    11. JUnit4 Runner
      JUnit4TestReference.run
      1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      1 frame
    12. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      5. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      5 frames