Created
August 1, 2015 22:41
-
-
Save jessecogollo/28860a5e61e0c888a39c to your computer and use it in GitHub Desktop.
schema mongoose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var mongoose = require('mongoose'), | |
Schema = mongoose.Schema; | |
var personSchema = new Schema({ | |
document: {type:String, require: true },//document is require in mongoose | |
name: String, | |
gender: String,//line 17 validates the values allowed. MASCULINO or FEMENINO | |
age:Number, | |
severity:Number, | |
typeDocument:String, | |
createAt: {type: Date, default: new Date()}, | |
updateAt: {type: Date, default: new Date()} | |
}); | |
personSchema.path('gender').validate(function (value) { | |
return /MASCULINO|FEMENINO/i.test(value); | |
}, 'example, Invalid gender'); | |
exports.schema = personSchema; | |
exports.model = mongoose.model('Person', personSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment