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

添加电影的时候报了一个错误,我有点懵逼,还请小伙伴看看,这到底是什么错

{ [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)


正在回答

2 回答

我之前也报这个错,我把movieObj改好以后就没了

var movieObj = req.req.body.movie

我自己改了是这样才能得到movieObj

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

TypeError: Cannot read property 'save' of undefined,意思是无save属性,看看你要存入的模块实例的原型是是否model

1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
node+mongodb 建站攻略(一期)
  • 参与学习       91860    人
  • 解答问题       889    个

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

进入课程

添加电影的时候报了一个错误,我有点懵逼,还请小伙伴看看,这到底是什么错

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