I created an app where people can upload some images of some themselves.
Now, In order to deal with cases where people can upload inappropriate images, I created a reporting system. What I'm doing is basically every time someone reports the image, the ID of the reporting person is added to an array in firestore
like this:
db
.collection( "Reports" )
.document( ImageID )
.update( "Reports", FieldValue.arrayUnion( UID ) );
Now, I want to set a rule that if for example, the size of the array is 5 (5 different people reports the image) that it will automatically delete that image from the cloud.
Is there any way I can do it instead of every time reading the array and check ist size?
Thank you
The most common way to do that would be through Cloud Functions, which are server-side code that is automatically triggered when (for this use-case) something is written to Firestore. See the documentation on Cloud Functions and the page on Firestore triggers.
An alternate (but more involved) would be to secure access through a query and security rules. In this scenario you'd:
reportCount
to the document, and ensure this gets updated in sync with the reports.reportCount
less than 5.As said, this is more involved in the amount of code you write, but the advantage is that no server-side code is involved, and that documents are immediately blocked when too many reports come in for them.