Hi Spring Data team !
Following my analysis in spring-projects/spring-data-mongodb#5216 on Kotlin DSL behaviors.
Currently, when using the Kotlin DSL for mongodb, we can use the div operator to query nested properties:
import org.springframework.data.mapping.div
mongoOperations.find<Book>(
Query(Book::author / Author::name regex "^H")
)
// { "author.name": /^H/ }
However, the div operator is now deprecated, with a recommendation to use the one from org.springframework.data.core.div. At the moment, if we replace the div operator with the new one, it generates the following query: { "name": /^H/ }
import org.springframework.data.core.div
mongoOperations.find<Book>(
Query(Book::author / Author::name regex "^H")
)
// { "name": /^H/ }
This behavior is incorrect, as it drops the parent path and may lead to invalid queries.
IMHO, it would be a good idea to extend the org.springframework.data.core.asString(property: KProperty<*>) function to support the previous org.springframework.data.mapping.KPropertyPath and org.springframework.data.mapping.KIterablePropertyPath types within the when statement. (see asString )
This would ensure that calls made through org.springframework.data.core.toDotPath() correctly handle both versions of the div operator.
Updating spring-data-mongodb to rely on org.springframework.data.core.toDotPath() would allow users to use either org.springframework.data.core.div or org.springframework.data.mapping.div while producing identical queries.
I think this would provide a smoother migration path for users.
Any thoughts ?
Regards,
Patouche
Hi Spring Data team !
Following my analysis in spring-projects/spring-data-mongodb#5216 on Kotlin DSL behaviors.
Currently, when using the Kotlin DSL for mongodb, we can use the
divoperator to query nested properties:However, the
divoperator is now deprecated, with a recommendation to use the one fromorg.springframework.data.core.div. At the moment, if we replace thedivoperator with the new one, it generates the following query:{ "name": /^H/ }This behavior is incorrect, as it drops the parent path and may lead to invalid queries.
IMHO, it would be a good idea to extend the
org.springframework.data.core.asString(property: KProperty<*>)function to support the previousorg.springframework.data.mapping.KPropertyPathandorg.springframework.data.mapping.KIterablePropertyPathtypes within the when statement. (see asString )This would ensure that calls made through
org.springframework.data.core.toDotPath()correctly handle both versions of thedivoperator.Updating spring-data-mongodb to rely on
org.springframework.data.core.toDotPath()would allow users to use eitherorg.springframework.data.core.divororg.springframework.data.mapping.divwhile producing identical queries.I think this would provide a smoother migration path for users.
Any thoughts ?
Regards,
Patouche