Skip to content

Invalid reference '_id' while grouping [DATAMONGO-2546] #3402

@spring-projects-issues

Description

@spring-projects-issues

itzvarman opened DATAMONGO-2546 and commented

I have data set after projecting project("name") which gave you following data

{ "_id": 1, "name":"Maths" },
{ "_id": 1, "name":"Maths" },
{ "_id": 2, "name":"Science" },
{ "_id": 2, "name":"Science" }

I try to group using

group("_id").first("name").as("name")

It throws Invalid reference _id error. But when I do like following its working fine

aggregationOperationContext -> {
  return new Document("$group",
             new Document("_id", "$_id").append("name", new Document("$first", "$name")));
}

Finally I projected the _id field also, then group("_id").first("name").as("name") working fine.

In my document class, I have private ObjectId _id;
 


Reference URL: https://stackoverflow.com/questions/61745356/group-by-id-doesnt-work-in-spring-data-mongodb?noredirect=1#comment109225421_61745356

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions