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
@@ -1904,8 +1904,6 @@ AggregationResults<TagCount> results = template.aggregate(aggregation, "tags", T
1904
1904
1905
1905
WARNING: Indexes are only used if the collation used for the operation matches the index collation.
1906
1906
1907
-
include::./mongo-json-schema.adoc[leveloffset=+1]
1908
-
1909
1907
<<mongo.repositories>> support `Collations` via the `collation` attribute of the `@Query` annotation.
1910
1908
1911
1909
.Collation support for Repositories
@@ -1946,186 +1944,7 @@ as shown in (1) and (2), will be included when creating the index.
1946
1944
TIP: The most specifc `Collation` outroules potentially defined others. Which means Method argument over query method annotation over doamin type annotation.
1947
1945
====
1948
1946
1949
-
[[mongo.jsonSchema]]
1950
-
=== JSON Schema
1951
-
1952
-
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].
1953
-
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
1980
-
embedded schema objects that describe properties and subdocuments.
1981
-
<2> `required` is a property that describes which properties are required in a document. It can be specified optionally, along with other
1982
-
schema constraints. See MongoDB's documentation on https://docs.mongodb.com/manual/reference/operator/query/jsonSchema/#available-keywords[available keywords].
1983
-
<3> `properties` is related to a schema object that describes an `object` type. It contains property-specific schema constraints.
1984
-
<4> `firstname` specifies constraints for the `firsname` field inside the document. Here, it is a string-based `properties` element declaring
1985
-
possible field values.
1986
-
<5> `address` is a subdocument defining a schema for values in its `postCode` field.
1987
-
====
1988
-
1989
-
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.
2007
-
<2> Configure required properties.
2008
-
<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(…)`.
2009
-
<4> Build the schema object. Use the schema to create either a collection or <<mongodb-template-query.criteria,query documents>>.
2010
-
====
2011
-
2012
-
There are already some predefined and strongly typed schema objects (`JsonSchemaObject` and `JsonSchemaProperty`) available
2013
-
through static methods on the gateway interfaces.
2014
-
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" }
2022
-
JsonSchemaProperty.named("birthdate").with(JsonSchemaObject.of(Type.dateType()).description("Must be a date"));
2023
-
----
2024
-
2025
-
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,
2026
-
2027
-
`CollectionOptions` provides the entry point to schema support for collections, as the following example shows:
0 commit comments