You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/mongodb.adoc
+1-182
Original file line number
Diff line number
Diff line change
@@ -1886,8 +1886,6 @@ AggregationResults<TagCount> results = template.aggregate(aggregation, "tags", T
1886
1886
1887
1887
WARNING: Indexes are only used if the collation used for the operation matches the index collation.
1888
1888
1889
-
include::./mongo-json-schema.adoc[leveloffset=+1]
1890
-
1891
1889
<<mongo.repositories>> support `Collations` via the `collation` attribute of the `@Query` annotation.
1892
1890
1893
1891
.Collation support for Repositories
@@ -1928,186 +1926,7 @@ as shown in (1) and (2), will be included when creating the index.
1928
1926
TIP: The most specifc `Collation` outroules potentially defined others. Which means Method argument over query method annotation over doamin type annotation.
1929
1927
====
1930
1928
1931
-
[[mongo.jsonSchema]]
1932
-
=== JSON Schema
1933
-
1934
-
As of version 3.6, MongoDB supports collections that validate documents against a provided https://docs.mongodb.com/manual/core/schema-validation/#json-schema[JSON Schema].
1935
-
The schema itself and both validation action and level can be defined when creating the collection, as the following example shows:
<1> JSON schema documents always describe a whole document from its root. A schema is a schema object itself that can contain
1962
-
embedded schema objects that describe properties and subdocuments.
1963
-
<2> `required` is a property that describes which properties are required in a document. It can be specified optionally, along with other
1964
-
schema constraints. See MongoDB's documentation on https://docs.mongodb.com/manual/reference/operator/query/jsonSchema/#available-keywords[available keywords].
1965
-
<3> `properties` is related to a schema object that describes an `object` type. It contains property-specific schema constraints.
1966
-
<4> `firstname` specifies constraints for the `firsname` field inside the document. Here, it is a string-based `properties` element declaring
1967
-
possible field values.
1968
-
<5> `address` is a subdocument defining a schema for values in its `postCode` field.
1969
-
====
1970
-
1971
-
You can provide a schema either by specifying a schema document (that is, by using the `Document` API to parse or build a document object) or by building it with Spring Data's JSON schema utilities in `org.springframework.data.mongodb.core.schema`. `MongoJsonSchema` is the entry point for all JSON schema-related operations. The following example shows how use `MongoJsonSchema.builder()` to create a JSON schema:
<1> Obtain a schema builder to configure the schema with a fluent API.
1989
-
<2> Configure required properties.
1990
-
<3> Configure the String-typed `firstname` field, allowing only `luke` and `han` values. Properties can be typed or untyped. Use a static import of `JsonSchemaProperty` to make the syntax slightly more compact and to get entry points such as `string(…)`.
1991
-
<4> Build the schema object. Use the schema to create either a collection or <<mongodb-template-query.criteria,query documents>>.
1992
-
====
1993
-
1994
-
There are already some predefined and strongly typed schema objects (`JsonSchemaObject` and `JsonSchemaProperty`) available
1995
-
through static methods on the gateway interfaces.
1996
-
However, you may need to build custom property validation rules, which can be created through the builder API, as the following example shows:
// "birthdate" : { "bsonType": "date", "description", "Must be a date" }
2004
-
JsonSchemaProperty.named("birthdate").with(JsonSchemaObject.of(Type.dateType()).description("Must be a date"));
2005
-
----
2006
-
2007
-
The Schema builder also provides support for https://docs.mongodb.com/manual/core/security-client-side-encryption/[Client-Side Field Level Encryption]. Please refer to <<mongo.jsonSchema.encrypted-fields>> for more information,
2008
-
2009
-
`CollectionOptions` provides the entry point to schema support for collections, as the following example shows:
0 commit comments