1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| function newID(indexName){
Counter.findAndModify(
{_id: indexName },
[],
{$inc:{count:1}},
{new:true},
function (err,obj) {
console.log(obj)
可以获取到obj.value.count,怎么写才能返回到外部函数?
}
怎么写能返回给函数?
}
app.post('/admin/movie/new',function (req, res) {
略...
if(id !== 'undefined'){
略...
}else{
_movie = new Movie({
_id:newID("movieId"),
title:movieObj.title,
doctor: movieObj.doctor,
country: movieObj.country,
year:movieObj.year,
poster:movieObj.poster,
language:movieObj.language,
flash:movieObj.flash,
summary:movieObj.summary
})
_movie.save(function (err, movie) {
if(err){
console.log(err)
}
res.redirect('/movie/'+ movie._id)
})
);
}
}); |