How to code in reactor to update a specific field in a cassandra DB record
How to code in reactor to update a specific field in a cassandra DB record
I am using ReactiveCassandraRepository and I can create new record as below.
public Mono<String> saveAbc(Abc toBeSaved) {
return abcRepository.save(toBeSaved).map(saved -> saved.getId());
}
But I could not imagine how to update a specific field in a DB record since 2 reactive operations (findById & save) are involved.
I wrote a code as below to create or update status if exists, but seems to be not working.
public Mono<String> saveAbc(Abc toBeSaved) {
return abcRepository.findById(toBeSaved.getId())
.map(current -> abcRepository.save(transform(toBeSaved, current)).map(saved -> saved.getId()))
.flatMap(id -> id);
}
private Abc transform(Abc toBeSaved, Abc current) {
if(current == null) {
return toBeSaved;
} else {
current.setStatus(toBeSaved.getStatus());
return current;
}
}
Can someone please assist on that?
No any error logged, but object is not persisting in DB.
– user3332279
21 hours ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
How is this not working? Do you see error messages?
– Lajos Arpad
Jun 29 at 11:30