Is there any way to do validation like NotNull, Size, etc through SpringData librarirs for MongoDB?
Asked
Active
Viewed 2,878 times
1
-
see here: http://stackoverflow.com/a/22583492/343802 – leo Apr 22 '16 at 13:18
2 Answers
3
As I'm sure you know, a lot of MongoDB validation has to be enforced in the software layer, since the database itself is schemaless. However, I don't think that validation is part of SpringData.
We'd need to know more about what technologies you're using in order to give a specific recommendation for how to do validation. Still, here are a few options (it looks like you're already familiar with some of them):
- If you're using Spring already, then consider using their validation API. For example, it supports the JSR-303 Bean Validation API, which can be a nice way to declare the validation constraints in the javabeans themselves.
- There's also the javax.validation Bean Validation framework.
1
You can use MongoEventListeners + JSR 303 validation for that. I described how to do it on my blog

Maciej Walkowiak
- 12,372
- 59
- 63