Tuesday, 15 January 2013

node.js - Mongoose findOne not completing -



node.js - Mongoose findOne not completing -

after trying debug myself , searching google, mongoose findone not completing! get's line , not end, until timeout 2 minutes later. here code in order of called

----------------routing

// process signup form app.post('/signup', passport.authenticate('local-signup', { successredirect : '/profile', // redirect secure profile section failureredirect : '/', // redirect home page if there error failureflash : true // allow flash messages }));

------------ passport processing

passport.use('local-signup', new localstrategy({ // default, local strategy uses username , password, override email usernamefield : 'email', passwordfield : 'password', passreqtocallback: true // allows pass in req our route (lets check if user logged in or not) }, function (req, email, password, done) { // asynchronous process.nexttick(function () { // whether we're signing or connecting account, we'll need // know if email address in use. usercontroller.finduserbyemail(email, function (existinguser) { console.log(existinguser); // check see if there's user email if (existinguser) homecoming done(null, false, req.flash('signupmessage', 'that email taken.')); // if we're logged in, we're connecting new local account. if (req.user) { var user = req.user; user.email = email; user.password = encrypt.encrypt(password); user.save(function (err) { if (err) throw err; homecoming done(null, user); }); } // we're not logged in, we're creating brand new user. else { console.log("there"); // create user user.createuser(req.body.username, email, req.body.username, password, "0", 1, function (result) { homecoming done(null, result); }); } }); }); }));

------------------created info client (usercontroller)

exports.finduserbyemail = function(email, callback){ user.findone({email : email}, function(err, result){ if(err){ throw err; }else{ callback(result); } }); };

------------------user schema

//user schema var userschema = mongoose.schema({ name : string, email : string, username : string, password : string, ip : string, //type of user. can user admin 0, user pupil 1, user presentor (professor) 2, (user invitee 3) ?. type : number }); //instance of schema var user = mongoose.model('user', userschema);

the code runs right before user.findone(); , hangs. adding debugging statements shows method called, never enters callback. sits waiting.

other queries other schema have worked fine, , homecoming quickly.

i've added error event listener mongoose , nil comes up.

my express server runs 1 time connection open, rules out.

any help can provide appreciated!

-stephen

ok, first of all, think you're overcomplicating this. first take @ mongoose statics: http://mongoosejs.com/docs/guide.html#statics

now, why need separate usercontroller? (and seeing not mvc controller, naming convention confusing -- consider renaming if intend maintain user , usercontroller separate). consider, why need method @ all? mean, why not invoke user.findone({email: "some email address"}) straight middleware function?

regardless of chosen style...

i think issue not getting reference user model in usercontroller before effort utilize it.

add line before phone call user.findone in usercontroller:

var user = mongoose.model('user');

see if works. (be sure models required before effort utilize them).

node.js mongodb express mongoose

No comments:

Post a Comment