User.find({ name: _user.name }, function(err, user) { if (err) { console.log(err); } console.log(user.length); if (user.length == 0) { console.log("thwww"); var user = new User(_user); user.save(function(err, user) { if (err) { console.log(err); } console.log('reg is ok'); req.session.warn = '注册成功,现在登录获得更好体验。'; return res.redirect('/signin'); }); } else { req.session.warn = '已经有人抢先注册这个用户了,亲换一个试试。'; return res.redirect('/signup'); } });
function seedDB(){ //add article data.forEach(function(seed){ Article.create(seed, function(err, article){ if(err){ console.log(err); }else{ Comment.create( { text: "This is the first article", author: "Author" }, function(err, comment){ if(err){ console.log(err); } else{ article.comments.push(comment); article.save(); console.log("Comment added"); } }); } }); }); }
console.log('Comment Created!') campground.comments.push(comment._id) campground.save()
if (err) throw err; favorite.favoriteDishes.push(favDishID); favorite.save( function (err, favorites) { if (err) throw err; console.log('Dish with ' + favDishID + ' id added to new list of favorites!'); result[0].save( function(err, favorites) { if (err) throw err; console.log('Dish with ' + favDishID + ' id added to new list of favorites!');
}else{ campground.comments.push(comment); campground.save(); console.log("Created New Comment!")