Linked Questions

Popular Questions

Firestore Rules - Validate if data exists in other collection

Asked by At

I'm currently working on my firestore rules and I need to validate the incoming data. Besides what I already have, I also need to validate if the incoming origin and tag fields exist in the collection origins and tags. I've found how to do so when using references but I'm using embedded data so I'm unsure how to exactly do it.

function incomingData() {
function validTicket() {
    return incomingData().email is string &&
    incomingData().description is string &&
    incomingData().address is string &&
    incomingData().location is string &&
    incomingData().postCode.matches('^[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]') &&
    incomingData().size() == 5 &&
    incomingData().hasAll(['email','description', 'address', 'location', 'postCode']) &&

In the tags collection, every document has a single value with the tag name. The same applies to the origins.

enter image description here

Related Questions