DATAMONGO-1891 - Improve $jsonSchema documentation.
Original pull request: #542.
This commit is contained in:
committed by
Mark Paluch
parent
1ad975de0a
commit
ee8436880b
@@ -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 <<mongodb-template-query.criteria,query documents>>.
|
||||
====
|
||||
|
||||
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`
|
||||
|
||||
Reference in New Issue
Block a user