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

Repository query keyword IS_EMPTY not supported #4606

Open
ssppooff opened this issue Jan 8, 2024 · 1 comment
Open

Repository query keyword IS_EMPTY not supported #4606

ssppooff opened this issue Jan 8, 2024 · 1 comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement

Comments

@ssppooff
Copy link

ssppooff commented Jan 8, 2024

The documentation for repository query keywords (link) mentions support for the IsEmpty keyword, however, it fails with "Unsupported keyword" when used.

Steps to reproduce
0) spring initializr:

  • Maven & Kotlin on Java 17
  • Spring Boot 3.2.1
  • Dependencies: MongoDB Reactive
  1. Inside file with @SpringBootApplication, add the code below
  2. Start the app (no need for a running Mongo instance to get the exception)
interface CustomRepository : ReactiveMongoRepository<CustomData, String> {
	fun findByIdIsEmpty(id: String): Mono<Boolean>
}

data class CustomData(val id: String)

@Component
class Demo(val customRepository: CustomRepository) {
	@Bean
	fun accessRepo() {
		customRepository.findByIdIsEmpty("non-existent").block()
	}
}

Result
Error creating bean 'accessRepo', caused by org.springframework.beans.BeanInstantiationException: Failed to instantiate [void]: Factory method 'accessRepo' threw exception with message: Unsupported keyword

The exception is thrown inside org.springframework.data.mongodb.repository.query.from (line number 254), because the switch-statement above (line 168) has no case for IS_EMPTY, even though the keyword is defined in org.springframework.data.repository.query.parser.Type.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 8, 2024
@christophstrobl
Copy link
Member

True, the documentation is misleading as the repository sections lists the generic overview from data-commons which holds the entire list of supported keywords.

Supporting IS_EMPTY would be an enhancement and we'd have to define it's behaviour given the various scenarios the MongoDB data model allows.

I could imagine using an $eq comparision to build the support. Like { field : { $eq : "" } } would be sufficient for simple String. Collections could be checked with { field: { $size: 0 } } and objects with { field : { $eq : {} } }. Numeric values, should error, though one might argue a stored null may be considered empty, but what about primitive types then. Generic types in the java domain model may also be tricky and we'd need to consider @Field(targetType=...) to pick the right format.

@mp911de mp911de added type: enhancement A general enhancement status: ideal-for-contribution An issue that a contributor can help us with and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants