Skip to content
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

@Collation annotation on documents, repositories or queries not interpreted #4535

Open
dirkbolte opened this issue Oct 23, 2023 · 2 comments
Assignees
Labels
in: repository Repositories abstraction type: bug A general bug

Comments

@dirkbolte
Copy link

dirkbolte commented Oct 23, 2023

I'm using Spring data mongo and want to use collations for various queries. The collations need to work with the default repository methods as well as with custom queries.

According to the reference doc and the #2755 , the following should work:

@Collation(value = "...")
data class SampleDocument(
    @field:MongoId
    var id: String? = null,
    val value: String
)

interface RepositoryWithCollationInQuery: CrudRepository<SampleDocument, String> {
    @Collation(value = "...")
    @Query(
        value = "{}",
        sort = """{ "value":  1}""",
    )
    fun findAllCollationInAnnotation(): List<SampleDocument>
}

But the collation is not evaluated. It is only evaluated when adding it to @Query directly.

A sample project with the expected usage (and failing tests) can be found here: https://github.com/dirkbolte/mongodb_collation_test

The following approaches were tried:

  • adding @Collation to the data class (failed)
  • adding @Collation to the repository interface (failed)
  • adding @Collation to the query method (failed)
  • specifying collation=... on the @Query annotation (worked)

I would expect that adding the @Collation annotation to repository and/or document would allow all repository methods to make use of it, especially when using findAll(pageable) of the default spring repository interfaces. When requiring @Query for everything, I would have to specify every query manually and explicitly, which doesn't feel right.

Versions:

  • Spring Boot: 3.1.5
  • Spring Data Mongo: 4.1.5
  • MongoDB: 6 (4 showed no differences)

For reference, the I asked the question on stack overflow as well, in case this is a user error.

@dirkbolte dirkbolte changed the title @Collation annotation on documents, repositories or queries not interpreted @Collation annotation on documents, repositories or queries not interpreted Oct 23, 2023
@dirkbolte dirkbolte changed the title @Collation annotation on documents, repositories or queries not interpreted @Collation annotation on documents, repositories or queries not interpreted Oct 23, 2023
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 23, 2023
@christophstrobl christophstrobl self-assigned this Oct 23, 2023
@christophstrobl
Copy link
Member

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

@christophstrobl
Copy link
Member

The custom query ones seem to fail due to duplicate test data.

Good catch on the inherited methods. BasicPersistentEntity did not properly consider @Collation but was only looking for @Document and the collation was not properly passed on in SimpleMongoRepository - we'll take care of that.

@christophstrobl christophstrobl added type: bug A general bug in: repository Repositories abstraction and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository Repositories abstraction type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants