Spring boot Webflux(Reactive MongoDb) Unique Validation

I tried to use the @Indexed(unique=true) annotation at my entity but it never throw an error for a duplicate value. The @postmapping is working good but no validation error.

Code Link: https://github.com/kuyabooo/reactiveMongoUniqueValidation.git User Entity Image

Upvotes: 0

Views: 562

Answers (1)

Pratik
Pratik

Reputation: 21

Do the fallowing Changes in Code

  1. add fallowing property
    spring.data.mongodb.auto-index-creation= true

  2. you always need to specify the name of Index before creating so change syntax of @Indexed
    @Indexed(name = "pratik_dandre_index",unique = true)

NOTE : you should use any name for @Indexed

Upvotes: 1

Related Questions