In my callback, I am attempting to test whether my call to Model.find() found any results. The record passed to the callback for Model.findOne(), is null but this does not seem to be the case for Model.find() which typically "finds" all matching records. So, what exactly is Model.find() passing?
Below are various tests I made to try to determine what is being passed to the callback as record:
author.model.find({userName: 'nameNotInDB'}, function(err, record)
{
if(err){console.log(err)
}else{
console.log(record); //~> []
console.log(record == []); //~> false
console.log(record == null); //~> false
console.log(record == undefined); //~> false
console.log(record == ''); //~> true
console.log(record === ''); //~> false
console.log(record == false); //~> true
console.log(record === false); //~> false
}
});
console.log(typeof record === typeof []) // True
Your test (record == []) fails because comparing complex types (objects and arrays) will only be true if they are referencing the same object.
Update, better test:
console.log(Array.isArray(record)) // True