title: How to check duplicate value when update in NodeJS?
body: <p>i have UPDATE function in controller to update the value, but i have a problem that how can i update value that must not have a duplicate value. So, i think to do that i need to check NAME, and BRAND. Let me illustrate as below:</p>
  <pre><code>// update car
  export async function updateCar(req, res) {
    try {
      const car = await Car.findByIdAndUpdate(req.params.car_id, req.body, {
        new: true,
      });
      if (!car) {
        return res.status(404).send();
      }
      res.status(200).send(car);
    } catch (error) {
      return res.status(500).json({
        success: false,
        message: &quot;Server error. Please try again.&quot;,
        error: error.message,
      });
    }
  }
  </code></pre>
  <p>How can i check that car NAME and BRAND must not duplicate while update. I hope anyone could help me and i very apprecaite it.</p>