以下是schema定义的字段,有"minLength": "{label}最小长度为{minLength}", 和"maxLength": "{label}最大长度为{maxLength}"
"name":{
"bsonType": "string",
"title": "姓名",
"label": "姓名",
"minLength": 2,
"maxLength": 17,
"trim": "both",
"errorMessage":{
"required": "{label}必填",//如果title无法解译,可以用label
"minLength": "{label}最小长度为{minLength}",
"maxLength": "{label}最大长度为{maxLength}"
}
},
调用方式
const db = uniCloud.database();
db.collection('resume_demo').add({
name: '发嘎斯豆腐干基材花木成畦手自栽花木成畦手自栽花木成畦手自栽',
birth_year: 1999,
tel: '13874198888',
email: '8632@qq.com'
})
.then(res => {
console.log(res);
}).catch(err => {
console.log(err);
})
不管姓名输入多长都会提示:
Error: 数据库验证失败:姓名最小长度为2