title: How to prevent duplicate document entries into firestore based on fields in Firestore rules
body: <p>I'm trying to prevent the creation of a new document if there is one that currently exists in the collection with two id fields with the same values as the incoming data.</p>
  
  <p>Right now, I'm trying to attempt this with Firestore rules. </p>
  
  <p>I've found way no way in the simulator to actually do this as I need to test the incoming data against every document in the collection. </p>
  
  <p>I'm not quite sure what I'm missing here...     </p>
  
  <pre><code>service cloud.firestore {
  
    match /databases/{database}/documents {
      match /{document=**} {
        allow read;
      }
  
      match /someCollection/{someCollectionID} {
          allow write: if existingData().someValue != incomingData().someValue &amp;&amp;
                                  existingData().anotherValue != incomingData().anotherValue
      }
    }
  
    function existingData() {
      return resource.data
    }
  
    function incomingData() {
      return request.resource.data
    }
  }
  </code></pre>