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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -