当前位置: 首页 > news >正文

跟公司产品做网站用什么程序做网站最好优化

跟公司产品做网站,用什么程序做网站最好优化,南通科技网站建设,公司网站制作与推广目录 官方文档 简介 SchemaType 示例 配置SchemaType规则 通用规则 特定schemaType规则 String Number Date Map monggose会根据shcemaType将文档值转换成指定的类型 官方文档 Mongoose v8.0.3: SchemaTypes 简介 SchemaTypes是在使用Mongoose时#xff0c;用于…目录 官方文档 简介 SchemaType 示例 配置SchemaType规则 通用规则 特定schemaType规则 String Number Date Map monggose会根据shcemaType将文档值转换成指定的类型 官方文档 Mongoose v8.0.3: SchemaTypes 简介 SchemaTypes是在使用Mongoose时用于定义MongoDB文档模型中字段的数据类型的一种概念。在Mongoose中每个字段都有一个关联的SchemaType它定义了该字段的数据类型、验证规则等信息。 SchemaType String、Number、Date、Buffer、Boolean、ObjectId、Array、Map、Dcimal128、Schema、Mixed、UUID 示例 const schema new mongoose.Schema({name: String,binary: Buffer,living: Boolean,updated: { type: Date, default: Date.now },age: { type: Number, min: 18, max: 65 },mixed: mongoose.Schema.Types.Mixed,_someId: mongoose.Schema.Types.ObjectId,decimal: mongoose.Schema.Types.Decimal128,array: [],ofString: [String],ofNumber: [Number],ofDates: [Date],ofBuffer: [Buffer],ofBoolean: [Boolean],ofMixed: [mongoose.Schema.Types.Mixed],ofObjectId: [mongoose.Schema.Types.ObjectId],ofArrays: [[]],ofArrayOfNumbers: [[Number]],nested: {stuff: { type: String, lowercase: true, trim: true }},map: Map,mapOfString: {type: Map,of: String} });// example useconst Thing mongoose.model(Thing, schema);const m new Thing; m.name Statue of Liberty; m.age 50; m.updated new Date; m.binary Buffer.alloc(0); m.living false; m.mixed { wang: { thing: i want } }; m.markModified(mixed); m._someId new mongoose.Types.ObjectId; m.array.push(1); m.ofString.push(strings!); m.ofNumber.unshift(1, 2, 3, 4); m.ofDates.addToSet(new Date); m.ofBuffer.pop(); m.ofMixed [1, [], three, { four: 5 }]; m.nested.stuff good; m.map new Map([[key, value]]); m.save(); 配置SchemaType规则 通用规则 required布尔或函数如果为true则代表该值必传default 默认值select布尔查询时是否投影validate函数属性值验证get 函数使用 Object.defineProperty() 定义该属性的自定义 getterset函数使用 Object.defineProperty() 定义该属性的自定义 setteralias字符串定义一个虚拟属性用于get、set此pathimmutable布尔、设置此path的值不可更改index布尔是否将此属性设置索引提高查询文档的速度unique布尔是否将此值定义为该集合唯一的属性值 const mongoose require(mongoose); const schema new mongoose.Schema({name: {type: String,select: true,required: true,validate: v v.length 4,get: v v aaaa,set: v aaaa v,alias: i,immutable: true} }); const CatModel mongoose.model(Cat, schema);async function stduyFn() {const cat new CatModel({name: sss});try {await cat.save();cat.name 111111cat.i dadsadasawait cat.save();console.log(cat.name)} catch (err) {} }stduyFn() alias会添加一个虚拟属性映射到path为name上当设置immutable为true更改cat.i和cat.name并不会成功更改。 查看SchemaType配置关系 mongoose.SchemaType是所有SchemaTyps的基类schema.path(field)是SchemaTyps的实例 console.log(schema.path(name)) console.log(mongoose.Schema.Types.String.prototype.__proto__ mongoose.SchemaType.prototype) // true console.log(schema.path(name) instanceof mongoose.SchemaType) // true console.log(schema.path(name) instanceof mongoose.Schema.Types.String) // true特定schemaType规则 String lowercase: 布尔是否始终对值调用 .toLowerCase()。如果设置为 true则始终将值转换为小写uppercase: 布尔是否始终对值调用 .toUpperCase()。如果设置为 true则始终将值转换为大写trim: 布尔是否始终对值调用 .trim()。如果设置为 true则始终将值的前导和尾随空格去除。match: 正则表达式检查值是否与给定的正则表达式匹配enum: 数组该数组列出了值的所有可能取值minLength: 数字检查值的长度是否不小于给定的数字maxLength: 数字检查值的长度是否不大于给定的数字 Number min: 数字检查值是否大于或等于给定的最小值max: 数字检查值是否小于或等于给定的最大值enum: 数组检查值是否严格等于给定数组中的一个值 Date min: 日期检查值是否大于或等于给定的最小日期max: 日期创建一个验证器检查值是否小于或等于给定的最大日期 Map ofmap的key类型默认为String可以用of指定SchemaType monggose会根据shcemaType将文档值转换成指定的类型 转Number const mongoose require(mongoose); const schema new mongoose.Schema({age: Number, }); const Car mongoose.model(Car, schema);async function stduyFn() {const cat new Car({ age: 15 });const cat1 new Car({ age: true })const cat2 new Car({ age: false })const cat3 new Car({ age: { valueOf: () 83 } })try {await cat.save();await cat1.save();await cat2.save();await cat3.save();} catch (err) {} } stduyFn() 转String const mongoose require(mongoose); const schema new mongoose.Schema({number: Number, }); const Car mongoose.model(Car, schema);async function stduyFn() {const cat new Car({ number: 1666 });const cat1 new Car({ number: 1555 });const cat2 new Car({ number: { valueOf: () 1032 } })try {await cat.save();await cat1.save();await cat2.save();} catch (err) {} } stduyFn() 转Boolean ​true、true、1、1、yes都为truefalse、false、0、0、no 都为false
http://www.zqtcl.cn/news/249522/

相关文章:

  • 优化网站流量商城网站建设软件
  • dw属于什么的网页制作工具网络建站优化科技
  • 百度网站首页的设计理念南京高新区规划建设局网站
  • 虚拟机做实验的网站网站以个人名义备案
  • 自定义表单网站网站建设营销型号的区别
  • 有个网站做彩盒的贵阳网站建设托管
  • 网站制作属于什么专业做网站需要什么配置服务器吗
  • 网站开发学习培训广州网站优化关键词公司
  • 毕节金海湖新区城乡建设局网站企业网站的步骤
  • 网站后台设计教程网站建设判断题
  • 珠海网站建设 金蝶天元建设集团有限公司李华
  • 海安市建设局网站成都官网seo技术
  • 网站建设策划书结束语wordpress付费版
  • 进口网站建设做网站用什么格式的图片
  • 青海省住房和城乡建设部网站进入网站空间
  • 做公司简介的开源网站企业seo多少费用
  • 学校网站建设工作方案昆明做网站词排名优化
  • 镇江企业做网站针对人群不同,网站做细分
  • 个人单页网站建设台州网站建设惠店
  • 专做婚礼logo的网站做搜狗pc网站快速排
  • 北京网站建设公司分享网站改版注意事项做网站需要多大空间
  • 主机网站建设制作天津西青区天气预报
  • 网站没有内容可以备案吗横向网站源码
  • 做的网站浏览器提示不安全站优化
  • dede移动端网站源码电子商务网站建设开题报告
  • 做网站价格多少优质做网站哪家好
  • 网站建设及推广服务的合同范本留言网站建设的报告
  • 工程师招聘网站做网站需要公司资质吗
  • 苏州模板网站建站开网店如何运营和推广
  • 换空间网站备案北京网页设计平台