Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate map keys in Firestore rules

How can I validate all keys in map in Firestore rules? Each key in map is an identifier related to a document.

Example:

User creates an invitation document with other documents access like this:

{
   "email": "[email protected]",
   "documents": {
      "document1": true,
      "document2": true,
      ...
   }
}

How can I check document1 exists in database (ie. in documents collection)?

like image 513
piotrpawlowski Avatar asked Apr 15 '26 05:04

piotrpawlowski


1 Answers

You can't write loops in security rules, so if you have an unknown number of documents to work with, you won't be able to validate them. Instead, consider using Cloud Functions to check the values after it's been added, and delete the invitation if it's not valid.

like image 73
Doug Stevenson Avatar answered Apr 17 '26 03:04

Doug Stevenson