@@ -124,39 +124,37 @@ builder methods:
124
124
- ``Schema::create()``: When creating a new collection
125
125
- ``Schema::table()``: When updating collection properties
126
126
127
- After you implement schema validation, the server allows you to run only
128
- those write operations which follow the validation rules. Use schema
129
- validation to restrict data types and value ranges of document fields in
130
- a specified collection .
127
+ You can use schema validation to restrict data types and value ranges of
128
+ document fields in a specified collection. After you implement schema
129
+ validation, the server restricts write operations that don't follow the
130
+ validation rules .
131
131
132
- Before creating a collection with schema validation rules, you must
133
- define a JSON schema.
132
+ You can pass the following parameters to ``jsonSchema()``:
134
133
135
- The schema is a JSON object that contains key-value pairs
136
- specifying the validation rules for your collection. At the top level,
137
- this object must include a ``$jsonSchema`` object. The ``$jsonSchema``
138
- object can include the following fields:
139
-
140
- - ``title``: Sets an optional title for the schema.
141
- - ``required``: Specifies a list of required fields for each document in your collection.
142
- - ``properties``: Sets property requirements for individual fields.
143
-
144
- To view a full list of JSON schema object fields, see :manual:`JSON Schema
145
- </reference/operator/query/jsonSchema/#json-schema>` in the {+server-docs-name+}.
146
-
147
- You can optionally pass the following parameters to ``jsonSchema()``:
134
+ - ``schema``: Array that specifies the validation rules for the
135
+ collection. To learn more about constructing a schema, see
136
+ the :manual:`$jsonSchema </reference/operator/query/jsonSchema/>`
137
+ reference in the {+server-docs-name+}.
148
138
149
139
- ``validationLevel``: Sets the level of validation enforcement.
150
140
Accepted values are ``"strict"`` (default) and ``"moderate"``.
141
+
151
142
- ``validationAction``: Specifies the action to take when invalid
152
143
operations are attempted. Accepted values are ``"error"`` (default) and
153
144
``"warn"``.
154
145
155
- This example demonstrates how to pass a JSON schema to the
146
+ This example demonstrates how to specify a schema in the
156
147
``jsonSchema()`` method when creating a collection. The schema
157
- validation specifies that documents in the ``pilots`` collection must
158
- contain the ``license_number`` field with an integer value between
159
- ``1000`` and ``9999``.
148
+ validation has the following specifications:
149
+
150
+ - Documents in the ``pilots`` collection must
151
+ contain the ``license_number`` field.
152
+
153
+ - The ``license_number`` field must have an integer value between
154
+ ``1000`` and ``9999``.
155
+
156
+ - If you attempt to perform invalid write operations, the server raises
157
+ an error.
160
158
161
159
.. literalinclude:: /includes/schema-builder/flights_migration.php
162
160
:language: php
@@ -166,8 +164,7 @@ contain the ``license_number`` field with an integer value between
166
164
167
165
If you attempt to insert a document into the ``pilots`` collection that
168
166
violates the schema validation rule, {+odm-long+} returns a
169
- :php:`BulkWriteException <mongodb-driver-exception-bulkwriteexception>`
170
- because the validation action is set to ``"error"``.
167
+ :php:`BulkWriteException <mongodb-driver-exception-bulkwriteexception>`.
171
168
172
169
.. _laravel-eloquent-collection-exists:
173
170
0 commit comments