Skip to content

Commit e7602ab

Browse files
jason-price-mongodbjason-price-mongodb
andauthored
DOCSP-36179-schema-validation-updates (#6156) (#6298)
* DOCSP-36179-schema-validation-updates * DOCSP-36179-schema-validation-updates * DOCSP-36179-schema-validation-updates * DOCSP-36179-schema-validation-updates * DOCSP-36179-schema-validation-updates * DOCSP-36179-schema-validation-updates * DOCSP-36179-schema-validation-updates * DOCSP-36179-schema-validation-updates * DOCSP-36179-schema-validation-updates * DOCSP-36179-schema-validation-updates * DOCSP-36179-schema-validation-updates * DOCSP-36179-schema-validation-updates --------- Co-authored-by: jason-price-mongodb <jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com>
1 parent 250956f commit e7602ab

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

source/core/schema-validation.txt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,20 @@ validation in the following scenarios:
5151
from accidentally misspelling an item name when entering sales data.
5252

5353
- For a students collection, ensure that the ``gpa`` field is always a
54-
positive number. This validation catches typos during data entry.
54+
positive number. This validation prevents errors during data entry.
5555

5656
When MongoDB Checks Validation
5757
------------------------------
5858

59-
When you create a new collection with schema validation, MongoDB checks
60-
validation during updates and inserts in that collection.
59+
After you add schema validation rules to a collection:
6160

62-
When you add validation to an existing, non-empty collection:
63-
64-
- Newly inserted documents are checked for validation.
65-
66-
- Documents already existing in your collection are not checked for
67-
validation until they are modified. Specific behavior for existing
68-
documents depends on your chosen validation level. To learn more, see
61+
- All document inserts must match the rules.
62+
- The schema validation level defines how the rules are applied to
63+
existing documents and document updates. To learn more, see
6964
:ref:`schema-specify-validation-level`.
7065

71-
Adding validation to an existing collection does not enforce validation
72-
on existing documents. To check a collection for invalid documents, use
73-
the :dbcommand:`validate` command.
66+
To find documents in a collection that don't match the schema validation
67+
rules, see :ref:`use-json-schema-query-conditions-find-documents`.
7468

7569
What Happens When a Document Fails Validation
7670
---------------------------------------------

source/core/schema-validation/specify-validation-level.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ MongoDB applies validation rules:
3131
- Behavior
3232

3333
* - ``strict``
34-
- (*Default*) MongoDB applies validation rules to all inserts and
35-
updates.
34+
- (*Default*) MongoDB applies the same validation rules to all
35+
document inserts and updates.
3636

3737
* - ``moderate``
38-
- MongoDB only applies validation rules to existing valid
39-
documents. Updates to invalid documents which exist prior to the
40-
validation being added are not checked for validity.
38+
- MongoDB applies the same validation rules to document inserts
39+
and updates to existing valid documents that match the
40+
validation rules. Updates to existing documents in the
41+
collection that don't match the validation rules aren't checked
42+
for validity.
4143

4244
Prerequisite
4345
------------
@@ -260,7 +262,7 @@ documents.
260262
upsertedCount: 0
261263
}
262264

263-
The output shows that:
265+
The output shows:
264266

265267
- The update fails for the document with ``_id: 1``. This document
266268
met the initial validation requirements, and MongoDB applies

source/core/schema-validation/use-json-schema-query-conditions.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ Both commands return the same result:
102102
}
103103
]
104104

105+
.. _use-json-schema-query-conditions-find-documents:
106+
105107
Find Documents that Don't Match the Schema
106108
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107109

108-
To find all documents do not satisfy the schema:, use
109-
:query:`$jsonSchema` with the :query:`$nor` operator:
110+
To find documents in a collection that don't match the schema validation
111+
rules, use :query:`$jsonSchema` with the :query:`$nor` operator. For
112+
example:
110113

111114
.. code-block:: javascript
112115

0 commit comments

Comments
 (0)