I am using Spring data couchbase with reactive repository. Calling findById method from reactive repository. Once while updating checking if record exists and another one while fetching by document id. Both cases passing the unique value which creates document id. Fetching document by value successfully retrieves data.While updating data using the same fetchMyValue method to check if document exists which always returns empty result. Both cases id string generated is same.
Below is the code snippet for reference.
public Mono<MyValue> fetchMyValue(final String id) {
String id = CommonUtil.buildDocumentKey(id); //same id
return repo.findById(id).flatMap(mo -> {
return Mono.just(mo);
}).switchIfEmpty(//error Handling);
}
Above method returns value from couchbase. But below one fetchMyValue always returns empty mono object and update logic is not executed.Always switchIfEmpty is executed.
public Mono<ResponseStatus> saveMyObject(final Mono<MyObject> value) {
return value.flatMap(myValue -> {
try {
if (null != myValue.getId()) {
fetchMyValue(myValue.getId())
//calling above method
//passing value which generates same id
.flatMap(mv -> {
//update logic
})
.switchIfEmpty(saveMyValue(myValue));
}
} catch (Exception e) {
//exception handling
}
Below is buildDocumentKey method
public static String buildDocumentKey(String type) {
return new StringBuilder()
.append(Constants.PREFIX).append(Constants.DELIMITER)
.append(type).toString();
}
Even copy pasting document key value from fetchMyValue and executong in couchbase query returns \n
empty if its from fetchMyValue->Save/Update method
returns a value if its directly from fetchMyValue
Both strings are same.Then why is couchbase not returning result while saving/update.Is my reactive coding not in place. Please help me on this have been struggling for a long time.