TypeError: Cannot read property '_id' of undefined
at /home/decade/code/test/app.js:226:25
at Layer.handle [as handle_request] (/home/decade/code/test/node_modules/express/lib/router/layer.js:95:5)
at next (/home/decade/code/test/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/home/decade/code/test/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/decade/code/test/node_modules/express/lib/router/layer.js:95:5)
at /home/decade/code/test/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/home/decade/code/test/node_modules/express/lib/router/index.js:330:12)
at next (/home/decade/code/test/node_modules/express/lib/router/index.js:271:10)
at jsonParser (/home/decade/code/test/node_modules/body-parser/lib/types/json.js:112:7)
at Layer.handle [as handle_request] (/home/decade/code/test/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/decade/code/test/node_modules/express/lib/router/index.js:312:13)
at /home/decade/code/test/node_modules/express/lib/router/index.js:280:7
at Function.process_params (/home/decade/code/test/node_modules/express/lib/router/index.js:330:12)
at next (/home/decade/code/test/node_modules/express/lib/router/index.js:271:10)
at urlencodedParser (/home/decade/code/test/node_modules/body-parser/lib/types/urlencoded.js:100:7)
at Layer.handle [as handle_request] (/home/decade/code/test/node_modules/express/lib/router/layer.js:95:5)
通过实时的在控制台输出,可以发现没有将数据插入到数据库中,因此
通过检查可以发现,在数据模式中出现了存储错误
PostSchema.pre('save',function(next){
if(this.isNew){
this.meta.createAt=this.meta.updateAt=Date.now();
}else{
this.meta.updateAt=Date.now();
}
next();
});