I'm using Mongoose:
user.find({username: 'xyz'}, function(err, doc){
if(err){
res.render('error', {errorMsg: "Error blah blah"})
}
});
I'm deliberately using a user who doesn't exist xyz and it's not triggering any errors, I thought it was because of Mongoose but then I tried in MongoDB shell and yes MongoDB won't return an error if a record doesn't exist.
>db.accounts.find({username: 'xyz'})
> // no error, blank line
How do I handle that? I want the execution of the script stop if a user doesn't exist.
find), or a null result (forfindOne).