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

Add 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

Add rules添加规则

To add a rule, click Add Rule.要添加规则,请单击“添加规则”。

Validation view
2

Enter your rules输入规则

To enter your rules, edit the start template that appears. For example, you can specify required fields and field types. For details, see JSON Schema Validation.要输入规则,请编辑显示的开始模板。例如,您可以指定必填字段和字段类型。有关详细信息,请参阅JSON模式验证

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.要确认应用验证规则,请单击“确认”。要返回,请单击“取消”。

Next Steps后续步骤

Learn More了解更多