Slide 19
Slide 19 text
https://pixnio.com/de/landschaften/blatt-blatter/grunes-blatt-flora-natur-baum-sommer-garten
License: PD
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Validators & Json Schema
19
Criteria criteria = where("name").exists(true).ne(null).type(2)
.and("age").exists(true).ne(null).type(16).gte(0).lte(125);
Validator validator = Validator.criteria(criteria);
MongoJsonSchema schema = MongoJsonSchema.builder()
.required("name", "age")
.properties(
string("name").minLength(1),
int32("age").gte(0).lte(125)
.build();
Validator validator = Validator.schema(schema);
{
"name" : {
"$exists" : true,
"$ne" : null,
"$type" : 2
},
"age" : {
"$exists" : true,
"$ne" : null,
"$type" : 16,
"$gte" : 0,
"$lte" : 125
}
}
{
"type": "object",
"required": [ "name", "age" ],
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"age": {
"bsonType": "int",
"minimum" : 0,
"exclusiveMinimum" : false,
"maximum" : 125,
"exclusiveMaximum" : false
}
}
}
spring-projects/spring-data-examples
mongodb/schema-validation