I use Spring-Boot 1.5.1
andMongoDB 3.4.6
I have a document MongoDB
that contains some annotation @Indexed(unique=true)
in some field.
@Document(collection="Product")
public class Product{
@Id
private String id;
@Indexed(unique=true)
private String name;
@Indexed(unique=true)
private String searchName;
If there is a duplicate name or searchName, it returns org.springframework.dao.DuplicateKeyException
.
Stacktrace:
Caused by: org.springframework.dao.DuplicateKeyException: E11000 duplicate key error index: Product.name dup key: { : "name" }; nested exception is com.mongodb.MongoException$DuplicateKey: E11000 duplicate key error index: Product.name dup key: { : "name" }
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:52)
How can we get the key to which the exception was sent.
Something like when we put @NotNull(message = "Product briefDescription cannot be null")
in some kind of folder, and it gives message
in exception
, but the attribute message
for annotation is @Indexed
missing.
How to do it?
source
share