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.59k stars 1.07k forks source link

`SpringDataMongodbQuery` and `SpringDataMongodbSerializer` apply mapping twice #4709

Closed bro0k closed 3 weeks ago

bro0k commented 1 month ago
# Entity class example
@Document(collection = "record")
public class Record {
    @Id
    private String id;

    @Field("embedded_object")
    private EmbeddedObject embeddedObject;
}

@Document(collection = "embedded_object")
public class EmbeddedObject {
    @Id
    private String id;
}

# Query code example
recordRepository.findAll(QRecord.record.embeddedObject.id.eq("64268a7b17ac6a00018bf312"), PageRequest.of(0,1))

# Expected correct result
find using query: { "embedded_object._id" : { "$oid" : "64268a6117ac6a00018bf30f"}} fields: Document{{}} 

# Actual incorrect result
find using query: { "embedded_object._id" : "64268a6117ac6a00018bf30f"} fields: Document{{}} 
mp911de commented 1 month ago

SpringDataMongodbSerializer used via QuerydslMongoPredicateExecutor applies field name customization twice. The resulting query above (used with the QueryMapper) is embedded_object._id while it should be embeddedObject.id. Removing field name mapping in SpringDataMongodbSerializer seems not enough as other components break.