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

Spring JIRA | Christine Chan | 3 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    The following query in mongo is as such: {code} db.auditErrorEvents.aggregate( {"$group":{_id:{ "eventID" : "$event.eventID" , "appID" : "$event.appID" , "eventUID" : "$event.eventUID" , "osPlatform" : "$event.osPlatform" , "deviceType" : "$event.deviceType"}}}, {"$group":{_id:{ "eventID" : "$_id.eventID" , "appID" : "$_id.appID" , "osPlatform" : "$_id.osPlatform" , "deviceType" : "$_id.deviceType"}, "count" : { "$sum" : 1}}} ); {code} Basically this is a distinct count of a field eventUID with grouping eventID, appID, osPlatform, deviceType. The {{MongoTemplate}} does not allow me to refer to the first grouping. {code} template.aggregate(newAggregation( group(from(field("eventID", "event.eventID"), field("appID", "event.appID"), field("eventUID", "event.eventUID"), field("osPlatform", "event.osPlatform"), field("deviceType", "event.deviceType"))), group(from(field("eventID", "_id.eventID"), field("appID", "_id.appID"), field("osPlatform", "_id.osPlatform"), field("deviceType"))).count().as("count")), collectionName(), GroupedCount.class); {code} {noformat} java.lang.IllegalArgumentException: Invalid reference '_id.eventID'! 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) {noformat}

    Spring JIRA | 3 years ago | Christine Chan
    java.lang.IllegalArgumentException: Invalid reference '_id.eventID'!
  2. 0

    The following query in mongo is as such: {code} db.auditErrorEvents.aggregate( {"$group":{_id:{ "eventID" : "$event.eventID" , "appID" : "$event.appID" , "eventUID" : "$event.eventUID" , "osPlatform" : "$event.osPlatform" , "deviceType" : "$event.deviceType"}}}, {"$group":{_id:{ "eventID" : "$_id.eventID" , "appID" : "$_id.appID" , "osPlatform" : "$_id.osPlatform" , "deviceType" : "$_id.deviceType"}, "count" : { "$sum" : 1}}} ); {code} Basically this is a distinct count of a field eventUID with grouping eventID, appID, osPlatform, deviceType. The {{MongoTemplate}} does not allow me to refer to the first grouping. {code} template.aggregate(newAggregation( group(from(field("eventID", "event.eventID"), field("appID", "event.appID"), field("eventUID", "event.eventUID"), field("osPlatform", "event.osPlatform"), field("deviceType", "event.deviceType"))), group(from(field("eventID", "_id.eventID"), field("appID", "_id.appID"), field("osPlatform", "_id.osPlatform"), field("deviceType"))).count().as("count")), collectionName(), GroupedCount.class); {code} {noformat} java.lang.IllegalArgumentException: Invalid reference '_id.eventID'! 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) {noformat}

    Spring JIRA | 3 years ago | Christine Chan
    java.lang.IllegalArgumentException: Invalid reference '_id.eventID'!

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Invalid reference '_id.eventID'!

      at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference()
    2. Spring Data MongoDB - Core
      GroupOperation.toDBObject
      1. org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:78)
      2. org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:62)
      3. org.springframework.data.mongodb.core.aggregation.GroupOperation.toDBObject(GroupOperation.java:300)
      3 frames