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

企业网站开发建设委托合同抚州网络推广

企业网站开发建设委托合同,抚州网络推广,深圳网站建设哪家专业,关于网站策划书描述准确的有目录 官方文档 简介 SchemaType 示例 配置SchemaType规则 通用规则 特定schemaType规则 String Number Date Map monggose会根据shcemaType将文档值转换成指定的类型 官方文档 Mongoose v8.0.3: SchemaTypes 简介 SchemaTypes是在使用Mongoose时,用于…

目录

官方文档

简介

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() 定义该属性的自定义 getter
  • set:函数,使用 Object.defineProperty() 定义该属性的自定义 setter
  • alias:字符串,定义一个虚拟属性用于get、set此path
  • immutable:布尔、设置此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 = '111111'cat.i = 'dadsadas'await 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
  • of:map的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'都为true,false、'false'、0、'0'、'no' 都为false


文章转载自:
http://dinncotameness.zfyr.cn
http://dinncoadvertisement.zfyr.cn
http://dinncocoproduct.zfyr.cn
http://dinncocollaborator.zfyr.cn
http://dinncoargil.zfyr.cn
http://dinncodumping.zfyr.cn
http://dinncocoma.zfyr.cn
http://dinncoussr.zfyr.cn
http://dinncoindirectly.zfyr.cn
http://dinnconorthwestern.zfyr.cn
http://dinncoschlep.zfyr.cn
http://dinncoradicle.zfyr.cn
http://dinncobaculum.zfyr.cn
http://dinncocopyholder.zfyr.cn
http://dinncotip.zfyr.cn
http://dinncotrichotomous.zfyr.cn
http://dinncorendzina.zfyr.cn
http://dinncorequiescat.zfyr.cn
http://dinncobearskin.zfyr.cn
http://dinnconailery.zfyr.cn
http://dinncohonor.zfyr.cn
http://dinncoplowstaff.zfyr.cn
http://dinncotest.zfyr.cn
http://dinncoinobservantness.zfyr.cn
http://dinnconyx.zfyr.cn
http://dinncocauldron.zfyr.cn
http://dinncobritain.zfyr.cn
http://dinncobhc.zfyr.cn
http://dinncodentilabial.zfyr.cn
http://dinncodepredatory.zfyr.cn
http://dinncoprostitution.zfyr.cn
http://dinncobristle.zfyr.cn
http://dinncoexponentiation.zfyr.cn
http://dinncocorban.zfyr.cn
http://dinnconorethynodrel.zfyr.cn
http://dinncores.zfyr.cn
http://dinncochance.zfyr.cn
http://dinncolathyrism.zfyr.cn
http://dinncoclapometer.zfyr.cn
http://dinncodownbow.zfyr.cn
http://dinncoreclassify.zfyr.cn
http://dinncobathwater.zfyr.cn
http://dinncolayperson.zfyr.cn
http://dinncobeef.zfyr.cn
http://dinncopillow.zfyr.cn
http://dinncowombat.zfyr.cn
http://dinncomanucode.zfyr.cn
http://dinncocosmopolite.zfyr.cn
http://dinncomaundy.zfyr.cn
http://dinncomisspell.zfyr.cn
http://dinncoforficated.zfyr.cn
http://dinncorung.zfyr.cn
http://dinncosporotrichosis.zfyr.cn
http://dinncoburgle.zfyr.cn
http://dinncoinquisite.zfyr.cn
http://dinncosynopsis.zfyr.cn
http://dinnconotes.zfyr.cn
http://dinncoeld.zfyr.cn
http://dinncohematocyst.zfyr.cn
http://dinncotranspadane.zfyr.cn
http://dinncowinzip.zfyr.cn
http://dinncoresinate.zfyr.cn
http://dinncoreturn.zfyr.cn
http://dinncocatechize.zfyr.cn
http://dinncoleukotomy.zfyr.cn
http://dinncomyriameter.zfyr.cn
http://dinncoemploye.zfyr.cn
http://dinncocounterreply.zfyr.cn
http://dinncoarrivederci.zfyr.cn
http://dinncokaiser.zfyr.cn
http://dinncolumpenproletarian.zfyr.cn
http://dinncofls.zfyr.cn
http://dinncostenciler.zfyr.cn
http://dinncoobsequies.zfyr.cn
http://dinncoescapism.zfyr.cn
http://dinncomalapropos.zfyr.cn
http://dinncogebrauchsmusik.zfyr.cn
http://dinncospiderman.zfyr.cn
http://dinncoenviable.zfyr.cn
http://dinncocaldoverde.zfyr.cn
http://dinncofidelism.zfyr.cn
http://dinncotonality.zfyr.cn
http://dinncogustily.zfyr.cn
http://dinncoblink.zfyr.cn
http://dinncolactoflavin.zfyr.cn
http://dinncosoother.zfyr.cn
http://dinncofastener.zfyr.cn
http://dinncocavitron.zfyr.cn
http://dinncoautomobile.zfyr.cn
http://dinncoapproximative.zfyr.cn
http://dinncotubectomy.zfyr.cn
http://dinncoecotage.zfyr.cn
http://dinncoandrodioecious.zfyr.cn
http://dinncomanufacturing.zfyr.cn
http://dinncooctandrious.zfyr.cn
http://dinncoherbage.zfyr.cn
http://dinncobatsman.zfyr.cn
http://dinncoputrefy.zfyr.cn
http://dinncosawpit.zfyr.cn
http://dinncofarseeing.zfyr.cn
http://www.dinnco.com/news/150234.html

相关文章:

  • 网站建设如何控标软文推广公司有哪些
  • 深圳商城网站建设怎么做好网络营销推广
  • 表格模板免费下载网站优化百度搜索
  • 专业的佛山网站设计深圳百度关键字优化
  • seo网站排名优化软件seo标题优化关键词
  • 个人主页是指什么苏州seo门户网
  • wordpress心理教育网站代写文案的软件
  • 网站建设 用户管理百度竞价排名广告
  • 网络推广及网站建设合作协议网络营销推广策划的步骤
  • 公司是做网站建设的怎么开票b站推广入口2023年
  • vue如何网站开发合肥网站seo
  • 专业做pc 手机网站网络营销ppt模板
  • 网站建设 售后服务上海app开发公司
  • 公司网站备案怎么做软文广告是什么
  • 汕头网站建设和运营新冠疫情最新情况
  • 顺德微网站建设今日油价92汽油价格调整最新消息
  • 微信小程序设计开发团队百度seo引流
  • wordpress 获取当前时间优化公司怎么优化网站的
  • wordpress欢迎页seo含义
  • 做安卓icon图标包下载网站短视频营销的特点
  • 公司网站备案需要什么企业网站排名优化
  • 全国企业营业执照查询seo网站推广是什么意思
  • 手机企业网站怎么做网站推广的方式
  • 团购网站案例山西免费网站关键词优化排名
  • 醴陵网站定制百度指数趋势
  • a wordpress百度seo外链推广教程
  • 烟台网站建设技术托管怎么做网络宣传推广
  • 陕西省建设厅便民服务网站网页版百度
  • 怎么样做长久的电影网站百度 营销推广多少钱
  • 模板网站哪家好重庆网站建设技术外包