I noticed that Model.find() seems to produce the same outcome as Model.find().exec(). Both seem to retrieve the appropriate record/document as illustrated in the following two snippets of code:
//without exec
export const getUser = async (req, res, next) => {
try{
let mongoDocument = await User.find({name: "OrphanAnnie"})
res.status(200).json(mongoDocument);
} catch (err) {
console.log(err)
}
}
//with exec
export const getUser = async (req, res, next) => {
try{
let mongoDocument = await User.find({name: "OrphanAnnie"}).exec()
res.status(200).json(mongoDocument);
} catch (err) {
console.log(err)
}
}
Which is the recommended approach? In Mongoose - What does the exec function do? the post suggests that with exec() a Mongoose query can be built without using callback syntax. But since the query seems to work without using exec() at all why bother using it?