title: How to add validation in firebase firestore to prevent adding duplicate doc id
body: <p>I am manually inserting document ID in firestore i.e document of cars</p>
  <pre><code>  //Example Doc
      cars:{
      chasisNumber :{
        chasisNumber:123dfs,
        carName: BMW 
       }
      }
    //Example Doc
  </code></pre>
  <p>In this code if i accidentally add the same <strong>chasis number</strong> again then it overrides the existing values which are store against the existing <strong>chasis number</strong></p>
  <pre><code>import db from &quot;./firebase&quot;;
  
  function ShowCars() {
  const [chasis, setChasis] = useState(&quot;&quot;);
  const [name, setName] = useState(&quot;&quot;);
  
  
  const addCar =(e)=&gt;{
  e.preventDefault();
  db.collection(&quot;cars&quot;).doc(chasis).set({
   chasisNumber:chasis, 
    carName:name
   });
  
  }
    return (
      &lt;div&gt;
        &lt;form&gt;
          &lt;input placeholder=&quot;chasis No&quot; type=&quot;text&quot; onChange={(e)=&gt;{setChasis(e.target.value)} value={chasis}/&gt;
          &lt;input placeholder=&quot;Car Name&quot; type=&quot;text&quot; onChange={(e)=&gt;{setName(e.target.value)} value={name}/&gt;
          &lt;button type=&quot;submit&quot; onClick={addCar}&gt;Add&lt;/button&gt;
        &lt;/form&gt;
      &lt;/div&gt;
    )
  }
  
  export default ShowCars;
  </code></pre>
  <p>i want to avoid passing same doc and in result it should put some msg as alert on the screen</p>