I have an object to save (to MongoDB), but before it I need to check if some conditions are true.
Object contains IDs to other objects. It looks like
"object": {
"id": "123",
"subobject1": { "id": "1" },
"subobject2": { "id": "2" }
}
Subobjects contain only id, other info is located in other collection, so I have to check is the information exist.
In block-style I can do something like
if (!languageRepository.exists(Example.of(wordSet.getNativeLanguage())).block()) {
throw new RuntimeException("Native language doesn't exist");
}
if (!languageRepository.exists(Example.of(wordSet.getTargetLanguage())).block()) {
throw new RuntimeException("Target language doesn't exist");
}
and only then I can save my object
return wordSetRepository.save(wordSet);
How can I do it in "reactive" style without blocking?