Sunday 1 May 2016

db.collection.find not working

On my project with node and mongodb db.collection.find just not working. In routes.js file there is a function getUser() that tried to find a user by user_id, but finds nothing. I tried to do the same with same parameters on console and everything works fine.How to invoke the error: go to your profile page, create an item and redirect back to the profile page, then refresh it. Because of that a profile.ejs file can't be executed.function getUser(user_id) { var items; User.find({'user.id': user_id}, function(err, users) { if(err) throw err; items = users; return items; }); } app.get('/profile', isLoggedIn, function (req, res) { wasMessageShown(app.locals.answerObj); console.log(req.user); var user; if(req.user.user.id){ user = req.user; } else { user = getUser(req.user.item.user_id); } res.render('profile.ejs', { user: user, messageSuccess: app.locals.answerObj.messageSuccess, messageFailure: app.locals.answerObj.messageFailure }); });

Submitted May 01, 2016 at 12:54PM by GodOfTheMetal

No comments:

Post a Comment