I have created an update route for a product. there are some fields that must be unique.
when creating a product I'm checking that like so
const emailExists = await Foodlancer.findOne({ email: values.email });
if (emailExists) {
return res.status(400).json({ error: 'Email already used' });
}
But I'm not sure how to check if email is already used when updating a product.
If I use the code above it returns true for the same object that we are updating.
Is there a way to exclude an object? I have looked at $ne and $nin but not sure how to use them in this case.
Any suggestions?