为了账号安全,请及时绑定邮箱和手机立即绑定

// 用新对象里的字段替换老的字段出问题 _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 建站攻略(一期)
  • 参与学习       91860    人
  • 解答问题       889    个

带你完整实现一个从前端到后端的项目,初中级前端开发工程师必学课程

进入课程

// 用新对象里的字段替换老的字段出问题 _movie = _.extend(movie, movieObj);

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信