As the topic title suggests, I’m trying to ascertain what should be returned if findOne
doesn’t get a match.
I did not see this scenario in the documentation.
From my coding test, it appears to be undefined
. Based on the mflix code base, getUser()
, I thought perhaps an error was supposed to be thrown:
static async getUser(email) {
// TODO Ticket: User Management
// Retrieve the user document corresponding with the user's email.
try {
return await users.findOne({ email: email })
} catch (e) {
console.error(`Unable to find user with email ${email}` );
return null
}
}
In my own code, when I run a test against this using an email not in the database, an error is not thrown and instead undefined
is returned to the calling function.
Did something change in the latest releases?