【发布时间】:2014-06-28 21:13:23
【问题描述】:
我在一个简单的 web 应用程序中使用 spring 数据。
我有一个对其中一个字段有唯一约束的简单文档:
@Document
@CompoundIndexes({ @CompoundIndex(name = "playerConstraint", def = "{ 'playerId': 1 }", unique = true)
public class InProgressGameRound extends AbstractDocument {
//...
}
问题是当我调用该文档的存储库时: this.repository.save(newRound);
数据库中已经存在 newRound.playerId - 我没有遇到任何异常! 程序计数器继续前进,即使文档没有真正保存(由于约束),似乎一切都很好
如果我尝试手动将相同的条目插入到 mongoDB 中 - 我会收到一个错误,指出约束不允许他插入。
如何验证保存是否有效(使用存储库)?
谢谢
【问题讨论】:
-
你解决过这个问题吗?
标签: java spring mongodb spring-data mongotemplate