diff --git a/src/main/asciidoc/reference/mongodb.adoc b/src/main/asciidoc/reference/mongodb.adoc index 685ce9ba1..84d0346b1 100644 --- a/src/main/asciidoc/reference/mongodb.adoc +++ b/src/main/asciidoc/reference/mongodb.adoc @@ -1487,7 +1487,7 @@ WARNING: Indexes are only used if the collation used for the operation and the i [[mongo.jsonSchema]] === JSON Schema -As of version 3.6 MongoDB supports collections that validate ``Document``s against a provided JSON Schema. +As of version 3.6 MongoDB supports collections that validate ``Document``s against a provided https://docs.mongodb.com/manual/core/schema-validation/#json-schema[JSON Schema]. The schema itself and both validation action and level can be defined when creating the collection. .Sample JSON schema @@ -1547,6 +1547,18 @@ MongoJsonSchema.builder() <1> <4> Build the schema object. Use the schema to either create a collection or <>. ==== +There are already some predefined strongly typed `JsonSchemaObject` and `JsonSchemaProperty` available via static methods on the gateway interfaces. +However there may arise the need to build custom property validation rules which can be done via builder API. + +[source,java] +---- +// "birthdate" : { "bsonType": "date" } +JsonSchemaProperty.named("birthdate").ofType(Type.dateType()); + +// "birthdate" : { "bsonType": "date", "description", "Must be a date" } +JsonSchemaProperty.named("birthdate").with(JsonSchemaObject.of(Type.dateType()).description("Must be a date")); +---- + `CollectionOptions` provides the entry point to schema support for collections. .Create collection with `$jsonSchema`