0
0
Firebasecloud~15 mins

Deleting documents in Firebase - Mini Project: Build & Apply

Choose your learning style9 modes available
Deleting documents in Firebase Firestore
📖 Scenario: You are managing a simple app that stores user profiles in Firebase Firestore. Sometimes, you need to remove a user profile when it is no longer needed.
🎯 Goal: Learn how to delete a specific document from a Firestore collection using Firebase SDK.
📋 What You'll Learn
Create a Firestore collection reference
Specify the document ID to delete
Use the Firebase SDK method to delete the document
Confirm the deletion code is correctly structured
💡 Why This Matters
🌍 Real World
Deleting documents is common when users remove their accounts or when data needs cleanup in apps using Firestore.
💼 Career
Understanding how to delete documents safely and correctly is essential for backend and full-stack developers working with Firebase.
Progress0 / 4 steps
1
Set up Firestore collection reference
Create a constant called usersCollection that references the Firestore collection named users using collection(db, 'users').
Firebase
Need a hint?

Use the collection function from Firebase Firestore and pass db and the collection name 'users'.

2
Specify the document ID to delete
Create a constant called userIdToDelete and set it to the string 'user123', which is the ID of the user document to delete.
Firebase
Need a hint?

Assign the exact string 'user123' to the constant userIdToDelete.

3
Create a document reference for deletion
Create a constant called userDocRef that references the document to delete by using doc(usersCollection, userIdToDelete).
Firebase
Need a hint?

Use the doc function with usersCollection and userIdToDelete to get the document reference.

4
Delete the document using Firebase SDK
Write an async function called deleteUserDocument that calls deleteDoc(userDocRef) to delete the document. Use await inside the function.
Firebase
Need a hint?

Define an async function and use await deleteDoc(userDocRef) inside it to delete the document.