Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue May 12, 2020 · 2 comments
Closed
Assignees
Labels
in: aggregation-framework Aggregation framework support type: bug A general bug

Comments

@spring-projects-issues
Copy link

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

@spring-projects-issues
Copy link
Author

Christoph Strobl commented

thanks for reporting - we'll make sure the default _id field does not have to be explicitly mentioned by the ProjectOperation

@christophstrobl
Copy link
Member

This issue has been addressed via #3542.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: aggregation-framework Aggregation framework support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants