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

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

在錄入電影信息中,跳轉詳情頁報錯TypeError: Cannot read property '_id' of undefined

http://img1.sycdn.imooc.com//5954a7e20001912608400408.jpg

怎么鏈接mongodb 數據庫???

正在回答

2 回答

我和改為:

//admin post movie

app.post('/admin/movie/new', function(req, res) {

var id = req.body['movie[_id]'];

var movieObj = req.body;

var _movie;


if(id !== 'undefined') {

Movie.findById(id, function(err, movie) {

if(err) {

console.log(err);

}

_movie = _.extend(movie, movieObj);


_movie.save(function(err, movie) {

if(err) {

console.log(err);

}

res,redirect('/movie/' + movie._id);

})

})


} else {

_movie = new Movie({

doctor: movieObj['movie[doctor]'],

title: movieObj['movie[title]'],

country: movieObj['movie[country]'],

language: movieObj['movie[language]'],

year: movieObj['movie[year]'],

poster: movieObj['movie[poster]'],

flash: movieObj['movie[flash]'],

summary: movieObj['movie[summary]']

});


_movie.save(function(err, movie) {

if(err) {

console.log(err);

}

res.redirect('/movie/' + movie._id);

})

}

})

能錄入

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

類型錯誤,_id是undefined,_id沒有數據,

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

舉報

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

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

進入課程

在錄入電影信息中,跳轉詳情頁報錯TypeError: Cannot read property '_id' of undefined

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

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

幫助反饋 APP下載

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

公眾號

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