mongodb - Mongoose - always return null instead of an error when no result found? -


why mongoose return null instead of error when no result found?

person.findone({ 'name': 'ghost' }, function (err, person) {   console.log(err); // null   if (err) return handleerror(err); }); 

the person 'ghost' not exist in db expecting error null instead. why? how can get error instead?

because mongoose return error when there error, not finding result not error. can handle response if got null, :

person.findone({ 'name': 'ghost' }, function (err, person) {   if(person === null) {      console.log('no results found');   }   if (err) return handleerror(err); }); 

or

person.findone({ 'name': 'ghost' }, function (err, person) {       if (err) {      return handleerror(err);   } else if (person) {      return person;   } else {     return 'no results 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 -