問(wèn)題: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()?? ?}})//添加靜態(tài)方法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
- 1 回答
- 0 關(guān)注
- 1486 瀏覽
添加回答
舉報(bào)
0/150
提交
取消