在录入电影信息中,跳转详情页报错TypeError: Cannot read property '_id' of undefined
怎么链接mongodb 数据库???
怎么链接mongodb 数据库???
2017-06-29
我和改为:
//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);
})
}
})
能录入
举报