Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable deleting collections and documents from firebase console

In Firebase's Firestore, a user with write access to a project can simply delete any document and even a whole collection with multiple documents with a single click. This is a major security problem as any of my team member may end up deleting a whole collection with millions of documents in under a minute, through the Firebase console.

Is there a way to disable this?

Deleting a whole collection with a click:

user can delete a whole collection

User can cherry pick and delete a document as well:

user can delete a specific document

like image 389
Harshit Agrawal Avatar asked May 16 '19 10:05

Harshit Agrawal


People also ask

Does firestore delete empty collections?

Nope, there is nothing in place to automatically delete empty documents, as you might have a valid reason for wanting those empty documents to exist.

How do I delete a collection in firebase?

To delete an entire collection or subcollection in Cloud Firestore, retrieve all the documents within the collection or subcollection and delete them. If you have larger collections, you may want to delete the documents in smaller batches to avoid out-of-memory errors.

How do I delete multiple documents in firebase?

To delete multiple documents, you can do a single batched write. The WriteBatch class has a delete() method for this purpose.


1 Answers

Collaborators to your project who have write permission to Firestore will be able to delete data, including collections. If you don't want a specific user to be able to delete collections, you should grant them view-only permission to the database in the project through the Users and permissions panel in the Firebase console.

To delete a collection I nowadays have to type the name of that collection after clicking delete. This is to make it less likely that a collaborator who should be able to delete data, deletes an entire collection accidentally.

Pop-up that is shown before deleting a collection

like image 152
Frank van Puffelen Avatar answered Oct 12 '22 18:10

Frank van Puffelen