美文网首页
CastError: Cast to Number faile

CastError: Cast to Number faile

作者: DecadeHeart | 来源:发表于2017-03-13 21:25 被阅读0次
    ValidationError: Movie validation failed
        at MongooseError.ValidationError (/home/decade/code/test/node_modules/mongoose/lib/error/validation.js:22:11)
        at model.Document.invalidate (/home/decade/code/test/node_modules/mongoose/lib/document.js:1410:32)
        at model.Document.set (/home/decade/code/test/node_modules/mongoose/lib/document.js:695:10)
        at model.Document.set (/home/decade/code/test/node_modules/mongoose/lib/document.js:540:18)
        at model.Document (/home/decade/code/test/node_modules/mongoose/lib/document.js:66:10)
        at model.Model (/home/decade/code/test/node_modules/mongoose/lib/model.js:41:12)
        at new model (/home/decade/code/test/node_modules/mongoose/lib/model.js:3191:11)
        at /home/decade/code/test/app.js:166:14
        at Layer.handle [as handle_request] (/home/decade/code/test/node_modules/express/lib/router/layer.js:95:5)
        at next (/home/decade/code/test/node_modules/express/lib/router/route.js:131:13)
        at Route.dispatch (/home/decade/code/test/node_modules/express/lib/router/route.js:112:3)
        at Layer.handle [as handle_request] (/home/decade/code/test/node_modules/express/lib/router/layer.js:95:5)
        at /home/decade/code/test/node_modules/express/lib/router/index.js:277:22
        at Function.process_params (/home/decade/code/test/node_modules/express/lib/router/index.js:330:12)
        at next (/home/decade/code/test/node_modules/express/lib/router/index.js:271:10)
        at /home/decade/code/test/node_modules/body-parser/lib/read.js:129:5
      message: 'Movie validation failed',
      name: 'ValidationError',
      errors: 
       { year: 
          { CastError: Cast to Number failed for value "asdad" at path "year"
              at MongooseError.CastError (/home/decade/code/test/node_modules/mongoose/lib/error/cast.js:19:11)
              at model.Document.set (/home/decade/code/test/node_modules/mongoose/lib/document.js:696:7)
              at model.Document.set (/home/decade/code/test/node_modules/mongoose/lib/document.js:540:18)
              at model.Document (/home/decade/code/test/node_modules/mongoose/lib/document.js:66:10)
              at model.Model (/home/decade/code/test/node_modules/mongoose/lib/model.js:41:12)
              at new model (/home/decade/code/test/node_modules/mongoose/lib/model.js:3191:11)
              at /home/decade/code/test/app.js:166:14
              at Layer.handle [as handle_request] (/home/decade/code/test/node_modules/express/lib/router/layer.js:95:5)
              at next (/home/decade/code/test/node_modules/express/lib/router/route.js:131:13)
              at Route.dispatch (/home/decade/code/test/node_modules/express/lib/router/route.js:112:3)
              at Layer.handle [as handle_request] (/home/decade/code/test/node_modules/express/lib/router/layer.js:95:5)
              at /home/decade/code/test/node_modules/express/lib/router/index.js:277:22
              at Function.process_params (/home/decade/code/test/node_modules/express/lib/router/index.js:330:12)
              at next (/home/decade/code/test/node_modules/express/lib/router/index.js:271:10)
              at /home/decade/code/test/node_modules/body-parser/lib/read.js:129:5
              at invokeCallback (/home/decade/code/test/node_modules/body-parser/node_modules/raw-body/index.js:262:16)
            message: 'Cast to Number failed for value "asdad" at path "year"',
            name: 'CastError',
            kind: 'Number',
            value: 'asdad',
            path: 'year',
            reason: [Object] } } }
    /home/decade/code/test/app.js:180
          res.redirect('/movie/'+movie._id);
                                      ^
    
    TypeError: Cannot read property '_id' of undefined
        at /home/decade/code/test/app.js:180:35
        at /home/decade/code/test/node_modules/mongoose/lib/document.js:1900:19
        at handleError (/home/decade/code/test/node_modules/mongoose/node_modules/hooks-fixed/hooks.js:40:22)
        at _next (/home/decade/code/test/node_modules/mongoose/node_modules/hooks-fixed/hooks.js:46:22)
        at fnWrapper (/home/decade/code/test/node_modules/mongoose/node_modules/hooks-fixed/hooks.js:186:18)
        at /home/decade/code/test/node_modules/mongoose/lib/schema.js:200:17
        at /home/decade/code/test/node_modules/mongoose/node_modules/kareem/index.js:127:16
        at _combinedTickCallback (internal/process/next_tick.js:67:7)
        at process._tickCallback (internal/process/next_tick.js:98:9)
    

    出错报错原因
    CastError: Cast to Number failed for value "asdad" at path "year" 类型不匹配 asdad不是number型

    相关文章

      网友评论

          本文标题: CastError: Cast to Number faile

          本文链接:https://www.haomeiwen.com/subject/qkiqnttx.html