1

Is there any way to do validation like NotNull, Size, etc through SpringData librarirs for MongoDB?

jtoberon
  • 8,706
  • 1
  • 35
  • 48
Darshan Patil
  • 1,049
  • 2
  • 13
  • 19

2 Answers2

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.
Community
  • 1
  • 1
jtoberon
  • 8,706
  • 1
  • 35
  • 48
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