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
2016-05-11
定義 MovieSchema ?的時候沒有收尾的} ?定義不完整 ? updateAt之后 ?只有json結束 ?整個的定義還沒結束
2016-05-11
嗯嗯,知道了,已改了。還是謝謝你