I recently came across the node.js/mongodb pattern which as I understand returns a promise.
collection.find({ ... }).exec()
I use in my code:
await collection.find({ ... })
How are these different? Should I be using:
await collection.find({ ... }).exec()
Here's what I currently use and it works w/o issue:
router.get('/me', auth, async (req, res) => {
const user = await User.findById(req.user.sub).select('email');
if (!user) return res.status(400).json({ "status": "error", "message": "This user no longer exists." });
res.json({ "status": "success", "user": user });
});