跪求大神帮忙解决TypeError: Cannot read property 'save' of undefined
折腾了一个晚上,还是搞不定,body-parser已经安装了。mongodb也安装好了,提交数据就出错。其他功能正常。
(node:10084) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
{ CastError: Cast to ObjectId failed for value "undefined" at path "_id" for model "Movie"
at MongooseError.CastError (E:\webapp\imooc\node_modules\mongoose\lib\error\cast.js:26:11)
at ObjectId.cast (E:\webapp\imooc\node_modules\mongoose\lib\schema\objectid.js:147:13)
at ObjectId.castForQuery (E:\webapp\imooc\node_modules\mongoose\lib\schema\objectid.js:187:15)
at cast (E:\webapp\imooc\node_modules\mongoose\lib\cast.js:229:32)
at Query.cast (E:\webapp\imooc\node_modules\mongoose\lib\query.js:2752:12)
at Query.findOne (E:\webapp\imooc\node_modules\mongoose\lib\query.js:1353:10)
at E:\webapp\imooc\node_modules\mongoose\lib\query.js:2310:21
at new Promise.ES6 (E:\webapp\imooc\node_modules\mongoose\lib\promise.js:45:3)
at Query.exec (E:\webapp\imooc\node_modules\mongoose\lib\query.js:2304:17)
at Function.findById (E:\webapp\imooc\schemas\movie.js:43:5)
at E:\webapp\imooc\app.js:75:9
at Layer.handle [as handle_request] (E:\webapp\imooc\node_modules\express\lib\router\layer.js:95:5)
at next (E:\webapp\imooc\node_modules\express\lib\router\route.js:131:13)
at Route.dispatch (E:\webapp\imooc\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (E:\webapp\imooc\node_modules\express\lib\router\layer.js:95:5)
at E:\webapp\imooc\node_modules\express\lib\router\index.js:277:22
message: 'Cast to ObjectId failed for value "undefined" at path "_id" for model "Movie"',
name: 'CastError',
stringValue: '"undefined"',
kind: 'ObjectId',
value: 'undefined',
path: '_id',
reason: undefined,
model:
{ [Function: model]
hooks: Kareem { _pres: {}, _posts: {} },
base:
Mongoose {
connections: [Object],
plugins: [],
models: [Object],
modelSchemas: [Object],
options: [Object] },
modelName: 'Movie',
model: [Function: model],
db:
NativeConnection {
base: [Object],
collections: [Object],
models: [Object],
config: [Object],
replica: false,
TypeError: Cannot read property 'save' of undefined
at Movie.findById (E:\webapp\imooc\app.js:81:10)
at E:\webapp\imooc\node_modules\mongoose\lib\query.js:2326:9
at newTickHandler (E:\webapp\imooc\node_modules\mpromise\lib\promise.js:234:18)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)