1
votes

I have Firestore document IDs stored in a firebase database node, and the security rules in firebase database need to only allow the deletion of and ID if the document it references in Firestore doesn't exist. Is there any way to do this? if not, is there a way to call a function from firebase database rules to check if the ID references an existing document in Firestore and have it return a value?

2
Your title mentions Firebase Realtime Database but the question only asks about Firestore. You might want to change the title.Philip

2 Answers

1
votes

No, you cannot. Security rules do not have access to Firestore, and while Firebase Functions have an onDelete trigger, they are executed after the changes are already implemented in the db.

0
votes

You do not say where the database is being accessed from (web or app) but you could call a cloud function with the document id that you want to delete and then the cloud function could check whether the data the id references exists and if it does not, then delete the id from the firestore collection.

You could also add any additional logic you want in the cloud function.

https://firebase.google.com/docs/functions/get-started

In addition

https://firebase.google.com/docs/firestore/extend-with-functions

talks about how to extend the firestore capabilities using cloud functions.