spring-projects / spring-data-mongodb

Provides support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-mongodb/
Apache License 2.0
1.62k stars 1.09k forks source link

Project problem with similar names #4509

Open OddyUlrich opened 1 year ago

OddyUlrich commented 1 year ago

Good afternoon, I am currently doing a project where I am using an "aggregation" to do a $lookup, a $unwind and finishing with a $project. To simplify the data and since I don't need all the information that $lookup brings me I use the project to get, , among other things, the id and some fields of the document to which I do $lookup.

The problem comes when I go to see the result of the query and the instance of the class where the data is, doesn't have the correct data. This is because if the name of the field in the $project has one similar or equal to the one in the value field, this value is not copied and I don't really understand why...

I attach a demo where in the file "TfgBackendApplication.java" you can use debugger to see the fields of an example where one field is wrong and the other is right, although they are also printed on the screen.

I'm sorry if this is a stupid question, but it's really taken me a while to realise this... demo.zip

christophstrobl commented 1 year ago

@OddyUlrich thanks for reporting and the reproducer - we'll have a look

christophstrobl commented 1 year ago

The string aggregation pipeline does no in depth analysis of the operations in use and attempts to map field names against the source domain type. Camel case splitting unfortunately leads to the false detection of ExerciseBattery.id for the path Exercise -> exerciseBattery -> id where it should just use exerciseBatteryId.