Skip to content

Commit 97a4dda

Browse files
authored
DOCSP-48249-compass-schema-validation (#732)
* DOCSP-48249-compass-schema-validation * rev * removes download modal * rev * fix ref typo * external review * internal review
1 parent 4a73dbf commit 97a4dda

File tree

8 files changed

+233
-30
lines changed

8 files changed

+233
-30
lines changed

source/add-validation-rules.txt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
.. _compass-add-validation-rules:
2+
3+
=====================
4+
Add Validation Rules
5+
=====================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
.. include:: /includes/validation-task-intro.rst
16+
17+
Steps
18+
-----
19+
20+
.. procedure::
21+
:style: normal
22+
23+
.. step:: Add rules
24+
25+
To add a rule, click :guilabel:`Add Rule`.
26+
27+
.. figure:: /images/compass/add-rules.png
28+
:figwidth: 720px
29+
:alt: Validation view
30+
31+
.. step:: Enter your rules
32+
33+
To enter your rules, edit the start template that appears. For
34+
example, you can specify required fields and field types. For
35+
details, see :ref:`<json-schema-validation>`.
36+
37+
.. step:: Apply rules
38+
39+
To apply the validation rules, click :guilabel:`Apply`. To go back,
40+
click :guilabel:`Cancel`.
41+
42+
.. step:: (*Optional*) Preview sample documents
43+
44+
You can preview sample documents that match your validation rules
45+
by clicking :guilabel:`Preview documents`.
46+
47+
.. step:: Confirm rules
48+
49+
To confirm applying the validation rules, click :guilabel:`Confirm`.
50+
To go back, click :guilabel:`Cancel`.
51+
52+
Next Steps
53+
~~~~~~~~~~
54+
55+
- :ref:`<compass-edit-validation-rules>`
56+
57+
Learn More
58+
----------
59+
60+
- :ref:`<compass-validation>`
61+
- :ref:`<compass-generate-validation-rules>`
62+
- :ref:`<compass-edit-validation-rules>`

source/edit-validation-rules.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
.. _compass-edit-validation-rules:
2+
3+
=====================
4+
Edit Validation Rules
5+
=====================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
.. include:: /includes/validation-task-intro.rst
16+
17+
Steps
18+
-----
19+
20+
.. procedure::
21+
:style: normal
22+
23+
.. step:: Enable editing
24+
25+
To enable editing, click :guilabel:`Edit rules`.
26+
27+
.. figure:: /images/compass/edit-rules.png
28+
:figwidth: 720px
29+
:alt: Edit rules in code block
30+
31+
.. step:: Make your edits
32+
33+
To edit the schema validation rules, click in the code block
34+
that the validation rules appear in. Confirm your schema appears
35+
as expected.
36+
37+
.. step:: Apply rules
38+
39+
To apply the validation rules, click :guilabel:`Apply`. To go back,
40+
click :guilabel:`Cancel`.
41+
42+
.. step:: (*Optional*) Preview sample documents
43+
44+
You can preview sample documents that match your validation rules
45+
by clicking :guilabel:`Preview documents`.
46+
47+
.. step:: Confirm rules
48+
49+
To confirm applying the validation rules, click :guilabel:`Confirm`.
50+
To go back, click :guilabel:`Cancel`.
51+
52+
53+
Learn More
54+
----------
55+
56+
- :ref:`<compass-validation>`
57+
- :ref:`<compass-generate-validation-rules>`
58+
- :ref:`<compass-add-validation-rules>`

source/generate-validation-rules.txt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.. _compass-generate-validation-rules:
2+
3+
=========================
4+
Generate Validation Rules
5+
=========================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
.. include:: /includes/validation-task-intro.rst
16+
17+
Steps
18+
-----
19+
20+
.. procedure::
21+
:style: normal
22+
23+
.. step:: Generate rules
24+
25+
To generate validation rules, click :guilabel:`Generate Rules`.
26+
27+
.. figure:: /images/compass/add-rules.png
28+
:figwidth: 720px
29+
:alt: Validation view
30+
31+
.. step: Inspect the rules
32+
33+
These rules will be enforced on updates and inserts to your
34+
collection. Make sure to carefully review the generated rules
35+
before applying them.
36+
37+
.. step:: Apply rules
38+
39+
To apply the validation rules, click :guilabel:`Apply`. To go back,
40+
click :guilabel:`Cancel`.
41+
42+
.. step:: (*Optional*) Preview sample documents
43+
44+
You can preview sample documents that match your validation rules
45+
by clicking :guilabel:`Preview documents`.
46+
47+
.. step:: Confirm rules
48+
49+
To confirm applying the validation rules, click :guilabel:`Confirm`.
50+
To go back, click :guilabel:`Cancel`.
51+
52+
Next Steps
53+
~~~~~~~~~~
54+
55+
- :ref:`<compass-add-validation-rules>`
56+
- :ref:`<compass-edit-validation-rules>`
57+
58+
Learn More
59+
~~~~~~~~~~
60+
61+
- :ref:`<compass-validation>`
62+
- :ref:`<compass-add-validation-rules>`
63+
- :ref:`<compass-edit-validation-rules>`

source/images/compass/add-rules.png

180 KB
Loading

source/images/compass/edit-rules.png

222 KB
Loading
198 KB
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The :guilabel:`Validation` tab allows you to manage
2+
:manual:`schema validation rules </core/document-validation>`
3+
for a collection.
4+
5+
Schema validation ensures that all documents in a
6+
collection follow a defined set of rules, such as conforming to a
7+
specific shape or only allowing a specified range of values in fields.
8+
9+
For details, see :ref:`<compass-validation>`.

source/validation.txt

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,52 +23,39 @@ Schema validation ensures that all documents in a
2323
collection follow a defined set of rules, such as conforming to a
2424
specific shape or only allowing a specified range of values in fields.
2525

26-
.. figure:: /images/compass/validation-view.png
26+
.. figure:: /images/compass/validation-tab.png
2727
:figwidth: 720px
2828
:alt: Validation view
2929

3030
.. _compass-update-validation:
31+
.. _compass-validation-rules:
3132

3233
Validation Rules
3334
----------------
3435

35-
The validation editor supports :manual:`JSON Schema validation
36-
</core/schema-validation/#json-schema>`, and validation with query
37-
expressions using :manual:`query operators </reference/operator/query>`.
38-
After you click the :guilabel:`Update` button, |compass-short| updates to
39-
display a document from your collection that passes the validation and a
40-
document that fails.
36+
The validation editor supports :ref:`JSON Schema validation
37+
<json-schema-validation>`, and validation with query expressions using
38+
:ref:`<query-operator-validation>`.
39+
40+
.. _json-schema-validation:
4141

4242
JSON Schema Validation
4343
~~~~~~~~~~~~~~~~~~~~~~
4444

45-
To specify JSON Schema validation, use the
46-
:manual:`$jsonSchema </reference/operator/query/jsonSchema>`
47-
operator.
48-
49-
.. code-block:: javascript
50-
51-
{
52-
$jsonSchema: {
53-
required: ['name', 'borough'], // the name and borough fields are required
54-
properties: {
55-
cuisine: {
56-
bsonType: "string",
57-
description: "must be a string"
58-
}
59-
}
60-
}
61-
}
62-
63-
The :manual:`$jsonSchema </reference/operator/query/jsonSchema>`
64-
operator supports various keywords to specify validation rules. For
45+
The :manual:`$jsonSchema </reference/operator/query/jsonSchema>`
46+
operator supports various keywords to specify validation rules. For
6547
example:
6648

6749
- The ``required`` array defines required fields in your document.
68-
6950
- The ``properties`` object defines rules for specific document
7051
fields.
7152

53+
To generate a JSON schema by analyzing existing sample data, see
54+
:ref:`<compass-generate-validation-rules>`.
55+
56+
Example
57+
```````
58+
7259
Consider the following example validation:
7360

7461
.. code-block:: javascript
@@ -133,6 +120,8 @@ For all available ``$jsonSchema`` keywords, refer to the
133120
:manual:`$jsonSchema </reference/operator/query/jsonSchema>` page in
134121
the MongoDB manual.
135122

123+
.. _query-operator-validation:
124+
136125
Validation using Query Operators
137126
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138127

@@ -183,19 +172,41 @@ For details on validation actions and levels, see
183172
</core/schema-validation/#specify-validation-rules>` in the MongoDB
184173
manual.
185174

186-
.. seealso::
175+
Get Started
176+
-----------
187177

188-
- :manual:`Schema Validation </core/schema-validation/>`
178+
- :ref:`<compass-generate-validation-rules>`
179+
- :ref:`<compass-add-validation-rules>`
180+
- :ref:`<compass-edit-validation-rules>`
189181

190182
Limitations
191183
-----------
192184

193185
The :guilabel:`Validation` tab is not available if you are connected to
194186
:atlas:`Atlas Data Federation </data-federation>`.
195187

188+
|compass-short| cannot validate a schema that has more than 1000
189+
distinct fields. If you try to validate a schema with more than 1000
190+
distinct fields, |compass-short| returns an error.
191+
196192
.. BEGIN-COMPASS-ONLY
197193

198194
In :guilabel:`MongoDB Compass Readonly Edition`, you can
199195
only view validation rules. Creating and editing validation rules
200196
is not permitted.
197+
201198
.. END-COMPASS-ONLY
199+
200+
Learn More
201+
----------
202+
203+
- :manual:`$jsonSchema </reference/operator/query/jsonSchema>`
204+
- :manual:`Schema Validation </core/schema-validation/>`
205+
206+
.. toctree::
207+
:titlesonly:
208+
209+
Generate Validation Rules </generate-validation-rules>
210+
Add Validation Rules </add-validation-rules>
211+
Edit Validation Rules </edit-validation-rules>
212+
Download Validation Rules </download-validation-rules>

0 commit comments

Comments
 (0)