DATAMONGO-1322 - Polishing.
Remove ValidationAction/Level and ValidationOptions duplicates. Rename ValidatorDefinition to Validator and Validator to ValidationOptions. Update and rename some of the tests. Also make sure to run the created validator document through the QueryMapper for value conversion and potential field mappings. Streamline Validator usage by providing plain Document and JsonSchema validator options next to the Criteria based one. Finally update the reference documentation. Original pull request: #525. Related pull request: #511. Related ticket: DATACMNS-1835.
This commit is contained in:
committed by
Mark Paluch
parent
2024b30059
commit
36614ef0ab
@@ -96,6 +96,23 @@ MongoDB 3.6 allows validation and querying of documents using JSON schema draft
|
||||
|
||||
Spring Data MongoDB supports MongoDB's specific JSON schema implementation to define and use schemas. See <<mongo.jsonSchema,JSON Schema>> for further details.
|
||||
|
||||
[[mongo.mongo-3.validation.query-expression]]
|
||||
==== Query Expression Validation
|
||||
|
||||
Next to the <<mongo.mongo-3.validation.json-schema>> as of version 3.2 MongoDB supports validating documents against a given query structure. The structure can be built using `Criteria` objects just the same way as they are used for defining queries.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
Criteria queryExpression = Criteria.where("lastname").ne(null).type(2)
|
||||
.and("age").ne(null).type(16).gt(0).lte(150);
|
||||
|
||||
Validator validator = Validator.criteria(queryExpression);
|
||||
|
||||
template.createCollection(Person.class, CollectionOptions.empty().validator(validator));
|
||||
----
|
||||
|
||||
NOTE: Field names used within the query expression are mapped to the domain types property names taking potential `@Field` annotations into account.
|
||||
|
||||
[[mongo.mongo-3.misc]]
|
||||
=== Other things to be aware of
|
||||
|
||||
|
||||
Reference in New Issue
Block a user