Skip to content

Instantly share code, notes, and snippets.

@jessecogollo
Created August 1, 2015 22:41
Show Gist options
  • Save jessecogollo/28860a5e61e0c888a39c to your computer and use it in GitHub Desktop.
Save jessecogollo/28860a5e61e0c888a39c to your computer and use it in GitHub Desktop.
schema mongoose
'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