0

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.

Right now, I'm trying to attempt this with Firestore rules.

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.

I'm not quite sure what I'm missing here...

service cloud.firestore {

  match /databases/{database}/documents {
    match /{document=**} {
      allow read;
    }

    match /someCollection/{someCollectionID} {
        allow write: if existingData().someValue != incomingData().someValue &&
                                existingData().anotherValue != incomingData().anotherValue
    }
  }

  function existingData() {
    return resource.data
  }

  function incomingData() {
    return request.resource.data
  }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Faballion
  • 11
  • 1
  • 5

0 Answers0