node.js - What does findOne() return exactly in mongoose -
you pass in callback:
function(err, found) { if(err) // checks see if there error else if (found) // checks if document exists }
to execute query "immediately". correct way check if document exists? how can tell if document exists or not? how can tell if there error executing query (suppose connection lost before database return results). i'm little confused , clarification appreciated.
what have work fine.
if there error, want throw error.
if query returned document, found default true.
you can proceed use found object inside second if statement.
to see if query successful no user found:
function(err, found) { if(err){ throw err; } if(found){ console.log(json.stringify(found)); }else{ console.log('the query successful, nothing found'); } }
Comments
Post a Comment