Skip to content

Commit e511159

Browse files
jason-price-mongodbjason-price-mongodb
and
jason-price-mongodb
authored
DOCSP-36179-schema-validation-updates (#6156)
* 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 <[email protected]>
1 parent b7bcd78 commit e511159

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

source/core/schema-validation.txt

+7-13
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,20 @@ validation in the following scenarios:
5555
from accidentally misspelling an item name when entering sales data.
5656

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

6060
When MongoDB Checks Validation
6161
------------------------------
6262

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

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

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

7973
What Happens When a Document Fails Validation
8074
---------------------------------------------

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

+8-6
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

+5-2
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)