In Firebase Cloud Firestore Security Rules Reference, we see that we can get a document using get()
function:
get()
takes a path and returns the resource at that path.
Is there any way to check if a value already exist in a document of a collection (like mapping documents to check their values)?
I need to check if there is already a document with the field token identical to the value I want to set. I have tried this, but data
is documented to be to a document, not a collection of documents:
service cloud.firestore {
match /databases/{database}/documents {
match /deviceTokens/{tokenId} {
allow read, write: if get(/databases/$(database)/deviceTokens).data.token != request.data.token;
}
}
}
{tokenId}
different from what you set indata.token
? – Juan LaratokenId
references to current document, I need to check all documents in the collection. – alessionossa