jeudi 25 juillet 2019

How can I query a mongoose database

I'm trying to build a login page on my website,after saving the signup details to a database collection on mongoose, i can,t seem to query the database to serve up an error if the user types in an email address that isn't on the database. When the user tries to login, i query his database using the email provided, i don't know how to query it by identifying the specific _id of the user account. please help!!!

Like i said, i tried searching for the users document by querying the database using the email provided,problem is, if the user types in an email that doesn't exist in the database, the code doesn't run as it can't serve up any info and the website just keeps loading until it crashes

This is my code below, app.post('/patLogin', function(req, res) {

const elogin = req.body.eLogin;
const plogin = req.body.pLogin;


Patsignup.findOne({}, function(err, docs) {
        if(elogin === doc.email && plogin === doc.password) {
          res.render('patDashboard', {fName: doc.fName, lName:doc.lName})
        }else {
            if(elogin != doc.email || plogin != doc.password) {
                res.render('patLoginFailure')
            }

    })

})

I expect that when the user types in an email that doesn't exist in the database, it throws an error or renders an error page, not just loading until the page crashes.How do i do this?




Aucun commentaire:

Enregistrer un commentaire