I want to implement Spring Security with MongoDB.
How can I define custom User schema?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One of the greatest awesomeness of MongoDB is that it is schemaless, i.e. you are not forced to use some predefined set of columns. Another MongoDB feature is lack of JOINs.
These two statements mean that you may construct any schema you want, but try to have all required info in one collection. For example I used schema like this in one of my applications:
You can use
_idfor any unique field of any type (not only ObjectId), I use it for logins. You just need to cover basicorg.springframework.security.core.userdetails.UserDetailsgetters with data from this schema, but also you can add additional fields to the implementing class.