Rest Meteor-节点简单模式验证数据以匹配模式

Rest Meteor-节点简单模式验证数据以匹配模式,rest,meteor,simple-schema,Rest,Meteor,Simple Schema,我想将我的restapi验证更改为节点简单模式,用于模式定义和collection2@core用于架构验证 我想使用个人模式来验证用户提供的数据 Schemas = {}; Schemas.Person = new SimpleSchema({ name: { type: String, label: "Person's Name", unique: true, max: 200 }, surname: {

我想将我的
restapi
验证更改为
节点简单模式
,用于模式定义和
collection2@core
用于架构验证

我想使用
个人模式
来验证用户提供的
数据

Schemas = {};
Schemas.Person = new SimpleSchema({
    name: {
        type: String,
        label: "Person's Name",
        unique: true,
        max: 200
    },
    surname: {
        type: String,
        unique: true,
        label: "person's surname"
    },
};

validData = API.utility.validate(data, Schemas.Person });

API: {
  utility: {
    validate: function(data, schema) {
      return "The SimpleSchema Validation";
    }
  }
};

本案例在附录中描述

使用模式定义,您只需执行以下操作:

Schemas.person.validate(data);
如果在此之后您想查看结果或错误:

Schemas.person.isValid();
Schemas.person.validationErrors();