I am studying mongoose, and I have a example of a query:
async findOne(condition, constraints) {
try {
let data = await User.findOne(condition, constraints ? constraints : null);
console.log(`findOne success--> ${data}`);
return data;
} catch (error) {
console.log(`findOne error--> ${error}`);
return error;
}
}
In my opinion,this code will catch errors when the method findOne won't work. Then I saw in the console there is a 'findOne success--> null' when the method findOne returns null. How can I make the try/catch work?