Skip to content

Transition to org.springframework.data.core.div in Kotlin DSL #3503

Description

@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 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: regressionA regression from a previous release

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions