Describe the bug
The implementation for existsById in com.azure.spring.data.cosmos.core.ReactiveCosmosTemplate indicates that a Mono emitting true if the element exists, or false if the element does not exist. However, the implementation checks if the result emitted by findById is null, which cannot happen, as an empty Mono is returned by findById in case no element is found.
Exception or Stack Trace
N/A
To Reproduce
Use existsById to look for an element that does not exist, and observe that an empty Mono is returned in place of a Mono emitting false.
Code Snippet
/**
* Exists
*
* @param id the id
* @param domainType the entity class
* @param containerName the container name
* @return Mono with a boolean or error
*/
public Mono<Boolean> existsById(Object id, Class<?> domainType, String containerName) {
return findById(containerName, id, domainType)
.flatMap(o -> Mono.just(o != null));
}
Expected behavior
Returned Mono should emit true if the element is present and false if the element is not present.
Screenshots
If applicable, add screenshots to help explain your problem.
Setup (please complete the following information):
- OS: N/A
- IDE: IntelliJ
- Library/Libraries: com.azure.spring:spring-cloud-azure-starter-data-cosmos:4.10.0
- Java version: N/A
- App Server/Environment: N/A
- Frameworks: Spring Boot
Additional context
https://github.com/reactive-streams/reactive-streams-jvm#user-content-2.13
https://stackoverflow.com/questions/69461051/why-cant-a-mono-hold-a-null
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
Describe the bug
The implementation for
existsByIdincom.azure.spring.data.cosmos.core.ReactiveCosmosTemplateindicates that aMonoemittingtrueif the element exists, orfalseif the element does not exist. However, the implementation checks if the result emitted byfindByIdisnull, which cannot happen, as an emptyMonois returned byfindByIdin case no element is found.Exception or Stack Trace
N/A
To Reproduce
Use
existsByIdto look for an element that does not exist, and observe that an emptyMonois returned in place of aMonoemittingfalse.Code Snippet
Expected behavior
Returned
Monoshould emittrueif the element is present andfalseif the element is not present.Screenshots
If applicable, add screenshots to help explain your problem.
Setup (please complete the following information):
Additional context
https://github.com/reactive-streams/reactive-streams-jvm#user-content-2.13
https://stackoverflow.com/questions/69461051/why-cant-a-mono-hold-a-null
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report