<分区>
我一直在使用 MongoDB 和 Spring Boot。我创建了一个小型网络应用程序,但似乎遇到了一个错误。在我将 Web 应用程序部署到 EC2 并设置好所有内容后,我尝试了不同的场景。一个是我和我的 friend 试图将同一个对象保存到数据库中。这应该是不可能的,因为在我的代码中我已经限制了它,所以它会出错。但不知何故,如果时机完美,我们都可以保存文档。我们使用我们的方法 contains
检查文档是否已经存在,但在这种情况下它似乎失败了。
/**
* @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();
}
如有任何关于如何解决此问题的建议,我们将不胜感激。