添加電影的時候報了一個錯誤,我有點懵逼,還請小伙伴看看,這到底是什么錯
{ [CastError: Cast to ObjectId failed for value "" at path "_id" for model "Movie"]
? message: 'Cast to ObjectId failed for value "" at path "_id" for model "Movie"',
? name: 'CastError',
? stringValue: '""',
? kind: 'ObjectId',
? value: '',
? path: '_id',
? reason: undefined,
? model:
? ?{ [Function: model]
? ? ?hooks: Kareem { _pres: {}, _posts: {} },
? ? ?base:
? ? ? Mongoose {
? ? ? ? connections: [Object],
? ? ? ? models: [Object],
? ? ? ? modelSchemas: [Object],
? ? ? ? options: [Object] },
? ? ?modelName: 'Movie',
? ? ?model: [Function: model],
? ? ?db:
? ? ? NativeConnection {
? ? ? ? base: [Object],
? ? ? ? collections: [Object],
? ? ? ? models: [Object],
? ? ? ? config: [Object],
? ? ? ? replica: false,
? ? ? ? hosts: null,
? ? ? ? host: null,
? ? ? ? port: null,
? ? ? ? user: null,
? ? ? ? pass: null,
? ? ? ? name: null,
? ? ? ? options: null,
? ? ? ? otherDbs: [],
? ? ? ? _readyState: 0,
? ? ? ? _closeCalled: false,
? ? ? ? _hasOpened: false,
? ? ? ? _listening: false },
? ? ?discriminators: undefined,
? ? ?fetch: [Function],
? ? ?findById: [Function],
? ? ?_events: { init: [Function], save: [Function] },
? ? ?_eventsCount: 2,
? ? ?schema:
? ? ? Schema {
? ? ? ? obj: [Object],
? ? ? ? paths: [Object],
? ? ? ? aliases: {},
? ? ? ? subpaths: {},
? ? ? ? virtuals: [Object],
? ? ? ? singleNestedPaths: {},
? ? ? ? nested: [Object],
? ? ? ? inherits: {},
? ? ? ? callQueue: [Object],
? ? ? ? _indexes: [],
? ? ? ? methods: {},
? ? ? ? statics: [Object],
? ? ? ? tree: [Object],
? ? ? ? query: {},
? ? ? ? childSchemas: [],
? ? ? ? plugins: [Object],
? ? ? ? s: [Object],
? ? ? ? options: [Object],
? ? ? ? '$globalPluginsApplied': true },
? ? ?collection:
? ? ? NativeCollection {
? ? ? ? collection: null,
? ? ? ? opts: [Object],
? ? ? ? name: 'movies',
? ? ? ? collectionName: 'movies',
? ? ? ? conn: [Object],
? ? ? ? queue: [],
? ? ? ? buffer: true,
? ? ? ? emitter: [Object] },
? ? ?Query: { [Function] base: [Object] },
? ? ?'$__insertMany': [Function],
? ? ?insertMany: [Function] } }
events.js:141
? ? ? throw er; // Unhandled 'error' event
? ? ? ^
TypeError: Cannot read property 'save' of undefined
? ? at D:\wabstrom\film\app.js:94:19
? ? at D:\wabstrom\film\node_modules\mongoose\lib\query.js:2843:9
? ? at tryCatcher (D:\wabstrom\film\node_modules\bluebird\js\main\util.js:26:23)
? ? at Promise._settlePromiseFromHandler (D:\wabstrom\film\node_modules\bluebird\js\main\promise.js:507:31)
? ? at Promise._settlePromiseAt (D:\wabstrom\film\node_modules\bluebird\js\main\promise.js:581:18)
? ? at Promise._settlePromises (D:\wabstrom\film\node_modules\bluebird\js\main\promise.js:697:14)
? ? at Async._drainQueue (D:\wabstrom\film\node_modules\bluebird\js\main\async.js:123:16)
? ? at Async._drainQueues (D:\wabstrom\film\node_modules\bluebird\js\main\async.js:133:10)
? ? at Immediate.Async.drainQueues [as _onImmediate] (D:\wabstrom\film\node_modules\bluebird\js\main\async.js:15:14)
? ? at processImmediate [as _immediateCallback] (timers.js:383:17)
2017-09-10
我之前也報這個錯,我把movieObj改好以后就沒了
var movieObj = req.req.body.movie
我自己改了是這樣才能得到movieObj
2017-09-02
TypeError: Cannot read property 'save' of undefined,意思是無save屬性,看看你要存入的模塊實例的原型是是否model