问题:MovieSchema.pre('save',function(next){
^^^^^^^^^^^
SyntaxError: Unexpected identifier
源代码:
var mongoose = require('mongoose')
//骨架模版
var MovieSchema = new mongoose.Schema({
doctor:String,
title:String,
language:String,
country:String,
year:Number,
summary:String,
flash:String,
poster:String,
meta:{
createAt:{
type:Date,
default:Date.now()
},
updateAt:{
type:Date,
default:Date.now()
}
}
//为模式增加方法
MovieSchema.pre('save',function(next){
if (this.isNew) {
this.meta.createAt = this.meta.updateAt = Date.now()
}else{
this.meta.updateAt = Date.now()
}
})
//添加静态方法
MovieSchema.statics ={
fetch:function(cb){
return this
.find({})
.sort('meta.updateAt')
.exec(cb)
},
findById:function(id,cb){
return this
.findOne({_id:id})
.exec(cb)
}
}
module.exports = MovieSchema
一头飞奔的猪
相关分类