You try to delete a document in Firestore using its path, but the document does not exist. What is the result?
const docRef = firestore.collection('users').doc('nonexistentDoc'); await docRef.delete();
Think about how Firestore handles deletions for documents that are not present.
Deleting a non-existent document in Firestore does not cause an error. The operation succeeds silently because the document is effectively already deleted.
Choose the Firestore security rule snippet that permits document deletion only when the user is signed in.
service cloud.firestore {
match /databases/{database}/documents {
match /items/{itemId} {
allow delete: if <condition>;
}
}
}Check how to verify if a user is signed in within Firestore rules.
The condition request.auth != null ensures the user is authenticated before allowing delete operations.
You have a Firestore collection with thousands of documents. What is the best approach to delete all documents efficiently?
Consider Firestore limits on batch operations and how to handle large data sets.
Firestore does not support deleting a whole collection at once. The recommended way is to delete documents in batches (max 500 per batch) using the Admin SDK for efficiency and to avoid timeouts.
What is the main security risk if Firestore rules allow any authenticated user to delete any document in a collection?
Think about the principle of least privilege and data ownership.
If delete rules are too permissive, users can remove data they should not control, leading to unauthorized data loss.
You delete a Firestore document that contains subcollections. What happens to the subcollections and their documents?
Consider Firestore's data model and how deletions propagate.
Deleting a document does not delete its subcollections. Subcollections remain and must be deleted separately if desired.