Docs Home / Compass / Interact with Your Data / Set Validation Rules

Edit Validation Rules编辑验证规则

The Validation tab allows you to manage schema validation rules for a collection.“验证”选项卡允许您管理集合的模式验证规则。

Schema validation ensures that all documents in a collection follow a defined set of rules, such as conforming to a specific shape or only allowing a specified range of values in fields.模式验证确保集合中的所有文档都遵循一组定义的规则,例如符合特定的形状或仅允许字段中的指定值范围。

For details, see Set Validation Rules for Your Schema.有关详细信息,请参阅为模式设置验证规则

Steps步骤

1

Enable editing启用编辑

To enable editing, click Edit rules.要启用编辑,请单击“编辑规则”。

Edit rules in code block
2

Make your edits进行编辑

To edit the schema validation rules, click in the code block that the validation rules appear in. Confirm your schema appears as expected.要编辑架构验证规则,请在验证规则显示的代码块中单击。确认架构按预期显示。

3

Apply rules应用规则

To apply the validation rules, click Apply. To go back, click Cancel.要应用验证规则,请单击“应用”。要返回,请单击“取消”。

4

(Optional) Preview sample documents(可选)预览示例文档

You can preview sample documents that match your validation rules by clicking Preview documents.通过单击“预览文档”,可以预览符合验证规则的示例文档。

5

Confirm rules确认规则

To confirm applying the validation rules, click Confirm. To go back, click Cancel.要确认应用验证规则,请单击“确认”。要返回,请单击“取消”。

Learn More了解更多