I've been using MongoDB and Spring Boot. I created a small webapp and I seem to hit a bug. After I deploy my web app to EC2 and have everything set up, I try different scenarios. One is where me and my friend try to save the same object to the database. This should not be possible as in my code I have restricted it, so it would get an error. But somehow, if timed perfectly, we both can save the document. We use our method contains
that checks if the document exists already but it seems to fail in this case.
/**
* @param id ID of the document we are looking for
* @return true or false based on if the Doc with given ID exists
*/
@Override
public boolean contains(String id) {
return eventModelRepo.findById(id).isPresent();
}
Any advice on how to fix this would be appreciated.