title: How can I check if the id already exist in React using firestore?
body: <p>This is the code where I add data to firestore.
  How can I check if idEveniment field already exist in collection?
  And if exist I dont want to add the new  collection.
  Maybe return an error ?</p>
  <pre><code>import { firestore } from 'firebase';
  
  // Add Eveniment
  export const addEveniment = data =&gt; async(dispatch, getState, {getFirestore}) =&gt; {
      
      const firestore = getFirestore();
      const userId = getState().firebase.auth.uid;
      dispatch({type: actions.ADD_EVENIMENT_START});
      try {
          const res = await firestore.collection('evenimente').doc(userId).get();
          
          const newEveniment = {
              idEveniment: data.idEveniment, 
              eveniment: data.eveniment,
          }
          if(!res.data()) {
              firestore.collection('evenimente').doc(userId).set({
                  evenimente: [newEveniment],
              });
          } else {
              firestore.collection('evenimente').doc(userId).update({
                  evenimente: [...res.data().evenimente, newEveniment],
              });
          }
          
  
          dispatch({type: actions.ADD_EVENIMENT_SUCCESS});
          return true;
      } catch(err) {
          dispatch({type: actions.ADD_EVENIMENT_FAIL, payload: err.message})
      }
          
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/jJ3pK.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jJ3pK.jpg" alt="Firestore Collection" /></a></p>