Firestore security rules check if reference exists : <p>I'm wondering how I could check if a document value is a reference to another document and the document exists using firebase security rules.</p>

<p>What I tried:</p>

<pre><code>function validate(document) {
    return exists(document.reference)
}

match /collection/{document} {
    allow read: if request.auth != null;
    allow create, update: if isAdmin(request.auth.uid) &amp;&amp; validate(request.resource.data);
}
</code></pre>

<p>As this didn't work, I tried to figure out what type <code>document.ref</code> is.
Unfortunately, it doesn't seem to have any type of the listed ones here:
<a href="https://firebase.google.com/docs/firestore/reference/security/?authuser=0#data_types" rel="noreferrer">https://firebase.google.com/docs/firestore/reference/security/?authuser=0#data_types</a></p>

<p>I tried <code>path</code> as it's the most obvious one to work with exists.
I didn't expect it to work.
Another guess was maybe <code>map</code> or <code>string</code>.
Both were incorrect.</p>

<p>As I don't have a clue what this could be and there is nothing documented how I can convert the reference to a path, I now have to ask here.</p>

<p>Has anyone found a solution to this?</p>

<p>TL;DR:</p>

<p>I need to check using Firestore security rules whether a reference saved in a document is present and it exists in the database.</p>

<p>Thanks,
Dennis</p>
