0
0
Firebasecloud~20 mins

Deleting documents in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firestore Deletion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
What happens when you delete a Firestore document that does not exist?

You try to delete a document in Firestore using its path, but the document does not exist. What is the result?

Firebase
const docRef = firestore.collection('users').doc('nonexistentDoc');
await docRef.delete();
AThe delete operation throws an error indicating the document was not found.
BThe delete operation retries automatically until the document exists.
CThe delete operation creates an empty document at that path.
DThe delete operation succeeds silently without error.
Attempts:
2 left
💡 Hint

Think about how Firestore handles deletions for documents that are not present.

Configuration
intermediate
2:00remaining
Which Firestore security rule allows deleting documents only if the user is authenticated?

Choose the Firestore security rule snippet that permits document deletion only when the user is signed in.

Firebase
service cloud.firestore {
  match /databases/{database}/documents {
    match /items/{itemId} {
      allow delete: if <condition>;
    }
  }
}
Arequest.auth != null
Brequest.auth == null
Crequest.auth.uid == 'admin'
Dtrue
Attempts:
2 left
💡 Hint

Check how to verify if a user is signed in within Firestore rules.

Architecture
advanced
2:00remaining
How to efficiently delete all documents in a large Firestore collection?

You have a Firestore collection with thousands of documents. What is the best approach to delete all documents efficiently?

AUse Firestore client SDK to delete documents with a single query.
BDelete the collection directly using a single delete() call on the collection reference.
CUse a batch delete with Firestore Admin SDK, deleting documents in chunks of 500.
DDelete documents one by one in a loop without batching.
Attempts:
2 left
💡 Hint

Consider Firestore limits on batch operations and how to handle large data sets.

security
advanced
2:00remaining
What security risk arises if Firestore delete rules allow all users to delete any document?

What is the main security risk if Firestore rules allow any authenticated user to delete any document in a collection?

AUsers can delete documents they do not own, causing data loss.
BUsers can read documents but cannot delete them.
CUsers can only delete their own documents, no risk involved.
DUsers can create new documents but not delete existing ones.
Attempts:
2 left
💡 Hint

Think about the principle of least privilege and data ownership.

🧠 Conceptual
expert
2:00remaining
What is the effect of deleting a Firestore document that has subcollections?

You delete a Firestore document that contains subcollections. What happens to the subcollections and their documents?

AThe document and all its subcollections and documents are deleted automatically.
BOnly the document is deleted; subcollections remain intact and accessible.
CThe delete operation fails if subcollections exist under the document.
DThe document is deleted and subcollections are archived automatically.
Attempts:
2 left
💡 Hint

Consider Firestore's data model and how deletions propagate.