課程
/前端開發
/Node.js
/node+mongodb 建站攻略(一期)
ReferenceError: _ is not defined ? ?at E:\i_movie-master\app.js:108:22 ? 修改電影出問題
2017-06-19
源自:node+mongodb 建站攻略(一期) 3-2
正在回答
?Cast to ObjectId failed for value "undefined" at path "_id"
$ node app.js
imooc started on port3000
(node:5188) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or
set the `useMongoClient` option if using `connect()` or `createConnection()`
(node:5188) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plu
g in your own promise library instead: http://mongoosejs.com/docs/promises.html
{ MongooseError: Cast to ObjectId failed for value "undefined" at path "_id"
? ? at CastError (E:\imooc\node_modules\mongoose\lib\error\cast.js:26:11)
? ? at ObjectId.cast (E:\imooc\node_modules\mongoose\lib\schema\objectid.js:149:13)
? ? at ObjectId.SchemaType._castForQuery (E:\imooc\node_modules\mongoose\lib\schematype.js:1048:15)
? ? at ObjectId.castForQuery (E:\imooc\node_modules\mongoose\lib\schema\objectid.js:189:15)
? ? at ObjectId.SchemaType.castForQueryWrapper (E:\imooc\node_modules\mongoose\lib\schematype.js:1014:15)
? ? at cast (E:\imooc\node_modules\mongoose\lib\cast.js:268:32)
? ? at model.Query.Query.cast (E:\imooc\node_modules\mongoose\lib\query.js:2993:12)
? ? at model.Query.Query.findOne (E:\imooc\node_modules\mongoose\lib\query.js:1397:10)
? ? at E:\imooc\node_modules\mongoose\lib\query.js:2806:21
? ? at new Promise.ES6 (E:\imooc\node_modules\mongoose\lib\promise.js:45:3)
? ? at model.Query.exec (E:\imooc\node_modules\mongoose\lib\query.js:2800:17)
? ? at Function.findById (E:\imooc\schemas\movie.js:44:5)
? ? at E:\imooc\app.js:69:9
? ? at Layer.handle [as handle_request] (E:\imooc\node_modules\express\lib\router\layer.js:95:5)
? ? at next (E:\imooc\node_modules\express\lib\router\route.js:137:13)
? ? at Route.dispatch (E:\imooc\node_modules\express\lib\router\route.js:112:3)
? 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],
? ? ? ? models: [Object],
? ? ? ? modelSchemas: [Object],
? ? ? ? options: [Object] },
? ? ?modelName: 'Movie',
? ? ?model: [Function: model],
? ? ?db:
? ? ? NativeConnection {
? ? ? ? base: [Object],
? ? ? ? collections: [Object],
? ? ? ? config: [Object],
? ? ? ? replica: false,
? ? ? ? hosts: null,
? ? ? ? host: 'localhost',
? ? ? ? port: 27017,
? ? ? ? user: undefined,
? ? ? ? pass: undefined,
? ? ? ? name: 'imooc',
? ? ? ? options: [Object],
? ? ? ? otherDbs: [],
? ? ? ? _readyState: 1,
? ? ? ? _closeCalled: false,
? ? ? ? _hasOpened: true,
? ? ? ? _listening: false,
? ? ? ? db: [Object] },
? ? ?discriminators: undefined,
? ? ?fetch: [Function: fetch],
? ? ?findById: [Function: findById],
? ? ?_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],
? ? ? ? '$globalPluginsApplied': true },
? ? ?collection:
? ? ? NativeCollection {
? ? ? ? collection: [Object],
? ? ? ? opts: [Object],
? ? ? ? name: 'movies',
? ? ? ? collectionName: 'movies',
? ? ? ? conn: [Object],
? ? ? ? queue: [],
? ? ? ? buffer: false,
? ? ? ? emitter: [Object] },
? ? ?Query: { [Function] base: [Object] },
? ? ?'$__insertMany': [Function],
? ? ?insertMany: [Function] } }
events.js:163
? ? ? throw er; // Unhandled 'error' event
? ? ? ^
TypeError: Cannot read property 'save' of undefined
? ? at E:\imooc\app.js:75:10
? ? at E:\imooc\node_modules\mongoose\lib\query.js:2823:9
? ? at newTickHandler (E:\imooc\node_modules\mpromise\lib\promise.js:234:18)
? ? at _combinedTickCallback (internal/process/next_tick.js:73:7)
? ? at process._tickCallback (internal/process/next_tick.js:104:9)
_ is not defined說明你沒有引入_。
var _ = require('underscore') 或者 var _ = require('lodash')。
或者直接用 Object.assign(movie, movieObj)
舉報
帶你完整實現一個從前端到后端的項目,初中級前端開發工程師必學課程
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-06-27
?Cast to ObjectId failed for value "undefined" at path "_id"
$ node app.js
imooc started on port3000
(node:5188) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or
set the `useMongoClient` option if using `connect()` or `createConnection()`
(node:5188) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plu
g in your own promise library instead: http://mongoosejs.com/docs/promises.html
{ MongooseError: Cast to ObjectId failed for value "undefined" at path "_id"
? ? at CastError (E:\imooc\node_modules\mongoose\lib\error\cast.js:26:11)
? ? at ObjectId.cast (E:\imooc\node_modules\mongoose\lib\schema\objectid.js:149:13)
? ? at ObjectId.SchemaType._castForQuery (E:\imooc\node_modules\mongoose\lib\schematype.js:1048:15)
? ? at ObjectId.castForQuery (E:\imooc\node_modules\mongoose\lib\schema\objectid.js:189:15)
? ? at ObjectId.SchemaType.castForQueryWrapper (E:\imooc\node_modules\mongoose\lib\schematype.js:1014:15)
? ? at cast (E:\imooc\node_modules\mongoose\lib\cast.js:268:32)
? ? at model.Query.Query.cast (E:\imooc\node_modules\mongoose\lib\query.js:2993:12)
? ? at model.Query.Query.findOne (E:\imooc\node_modules\mongoose\lib\query.js:1397:10)
? ? at E:\imooc\node_modules\mongoose\lib\query.js:2806:21
? ? at new Promise.ES6 (E:\imooc\node_modules\mongoose\lib\promise.js:45:3)
? ? at model.Query.exec (E:\imooc\node_modules\mongoose\lib\query.js:2800:17)
? ? at Function.findById (E:\imooc\schemas\movie.js:44:5)
? ? at E:\imooc\app.js:69:9
? ? at Layer.handle [as handle_request] (E:\imooc\node_modules\express\lib\router\layer.js:95:5)
? ? at next (E:\imooc\node_modules\express\lib\router\route.js:137:13)
? ? at Route.dispatch (E:\imooc\node_modules\express\lib\router\route.js:112:3)
? 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],
? ? ? ? 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: 'localhost',
? ? ? ? port: 27017,
? ? ? ? user: undefined,
? ? ? ? pass: undefined,
? ? ? ? name: 'imooc',
? ? ? ? options: [Object],
? ? ? ? otherDbs: [],
? ? ? ? _readyState: 1,
? ? ? ? _closeCalled: false,
? ? ? ? _hasOpened: true,
? ? ? ? _listening: false,
? ? ? ? db: [Object] },
? ? ?discriminators: undefined,
? ? ?fetch: [Function: fetch],
? ? ?findById: [Function: findById],
? ? ?_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: [Object],
? ? ? ? opts: [Object],
? ? ? ? name: 'movies',
? ? ? ? collectionName: 'movies',
? ? ? ? conn: [Object],
? ? ? ? queue: [],
? ? ? ? buffer: false,
? ? ? ? emitter: [Object] },
? ? ?Query: { [Function] base: [Object] },
? ? ?'$__insertMany': [Function],
? ? ?insertMany: [Function] } }
events.js:163
? ? ? throw er; // Unhandled 'error' event
? ? ? ^
TypeError: Cannot read property 'save' of undefined
? ? at E:\imooc\app.js:75:10
? ? at E:\imooc\node_modules\mongoose\lib\query.js:2823:9
? ? at newTickHandler (E:\imooc\node_modules\mpromise\lib\promise.js:234:18)
? ? at _combinedTickCallback (internal/process/next_tick.js:73:7)
? ? at process._tickCallback (internal/process/next_tick.js:104:9)
2017-06-20
_ is not defined說明你沒有引入_。
var _ = require('underscore') 或者 var _ = require('lodash')。
或者直接用 Object.assign(movie, movieObj)