亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

// 用新對象里的字段替換老的字段出問題 _movie = _.extend(movie, movieObj);

http://img1.sycdn.imooc.com//59473e2f0001c78913120810.jpgReferenceError: _ is not defined ? ?at E:\i_movie-master\app.js:108:22 ? 修改電影出問題

正在回答

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],

? ? ? ? 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)


0 回復 有任何疑惑可以回復我~

_ is not defined說明你沒有引入_。

var _ = require('underscore') 或者 var _ = require('lodash')。

或者直接用 Object.assign(movie, movieObj)

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
node+mongodb 建站攻略(一期)
  • 參與學習       91828    人
  • 解答問題       921    個

帶你完整實現一個從前端到后端的項目,初中級前端開發工程師必學課程

進入課程

// 用新對象里的字段替換老的字段出問題 _movie = _.extend(movie, movieObj);

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號