栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

最小和最大带数字的猫鼬行为

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

最小和最大带数字的猫鼬行为

该验证可以帮助你。下面是一个示例。

var min = [0, 'The value of path `{PATH}` ({VALUE}) is beneath the limit ({MIN}).'];var max = [1, 'The value of path `{PATH}` ({VALUE}) exceeds the limit ({MAX}).'];var numberschema = new mongoose.Schema({    n: {type: Number, min: min, max: max} });var numberschema = mongoose.model('number', numberschema, 'number');var insertdocuments = function(db) {     var a = new numberschema({        n: 5    });    console.log(a);    a.validate(function(err) {        if (err) console.log(err);    });    a.save(function (err, ack) {        if (err) { console.log('Mongoose save error : ' + err);        } else {  console.log('Mongoose save successfully...');         }    }); };

尝试插入时

5
,出现以下错误

{ [ValidationError: Validation failed]  message: 'Validation failed',  name: 'ValidationError',  errors:   { n:      { [ValidatorError: The value of path `n` (5) exceeds the limit (1).]        message: 'The value of path `n` (5) exceeds the limit (1).',        name: 'ValidatorError',        path: 'n',        type: 'max',        value: 5 } } }Mongoose save error : ValidationError: The value of path `n` (5) exceeds the limit (1).

尝试插入时

abc
,出现以下错误

Mongoose save error : CastError: Cast to number failed for value "abc" at path "n"


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/446481.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号