課程
/前端開發
/Node.js
/node+mongodb 建站攻略(一期)
怎么鏈接mongodb 數據庫???
2017-06-29
源自:node+mongodb 建站攻略(一期) 3-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) {
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]']
});
res.redirect('/movie/' + movie._id);
能錄入
類型錯誤,_id是undefined,_id沒有數據,
舉報
帶你完整實現一個從前端到后端的項目,初中級前端開發工程師必學課程
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-07-28
我和改為:
//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);
})
}
})
能錄入
2017-06-30
類型錯誤,_id是undefined,_id沒有數據,