Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the soft delete pattern in MongoDB?
Soft delete means marking a document as deleted without removing it from the database. This is usually done by adding a field like isDeleted: true instead of deleting the document.
Click to reveal answer
beginner
Why use soft delete instead of hard delete?
Soft delete helps keep data for recovery, auditing, or history. It avoids losing data permanently and allows easy undo of deletions.
Click to reveal answer
beginner
How do you query only active (not deleted) documents in MongoDB with soft delete?
Add a filter like { isDeleted: { $ne: true } } to your query to exclude documents marked as deleted.
Click to reveal answer
beginner
What field is commonly added to implement soft delete in MongoDB?
A boolean field like isDeleted or a date field like deletedAt is added to mark deletion status.
Click to reveal answer
intermediate
How can you permanently remove soft deleted documents later?
Use a query like db.collection.deleteMany({ isDeleted: true }) to clean up documents marked as deleted.
Click to reveal answer
What does soft delete do in MongoDB?
AMarks documents as deleted without removing them
BImmediately removes documents from the database
CBacks up documents before deleting
DEncrypts documents before deletion
✗ Incorrect
Soft delete marks documents as deleted (e.g., with isDeleted: true) but keeps them in the database.
Which field is commonly used to mark a document as deleted in soft delete?
Ausername
BcreatedAt
CisDeleted
Dpassword
✗ Incorrect
The isDeleted field is commonly added to indicate if a document is soft deleted.
How do you exclude soft deleted documents in a MongoDB query?
A{ isDeleted: false }
B{ isDeleted: true }
C{ deletedAt: null }
D{ isDeleted: { $ne: true } }
✗ Incorrect
Using { isDeleted: { $ne: true } } filters out documents marked as deleted.
What is a benefit of using soft delete?
AAllows data recovery after deletion
BMakes queries faster
CReduces database size
DEncrypts data automatically
✗ Incorrect
Soft delete keeps data so you can recover it if needed.
How can you permanently remove soft deleted documents?
AInsert new documents
BUse deleteMany with { isDeleted: true }
CUpdate documents to isDeleted: false
DUse findOneAndUpdate
✗ Incorrect
deleteMany with { isDeleted: true } removes all soft deleted documents permanently.
Explain the soft delete pattern in MongoDB and why it is useful.
Think about how you keep old files instead of throwing them away immediately.
You got /3 concepts.
Describe how to query only active documents when using soft delete in MongoDB.
How do you find files that are not marked as deleted?
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the soft delete pattern in MongoDB?
easy
A. To encrypt data before deletion
B. To permanently remove data immediately
C. To backup data before deletion
D. To mark data as deleted without actually removing it from the database
Solution
Step 1: Understand soft delete concept
Soft delete means marking data as deleted but keeping it in the database.
Step 2: Compare options
Only To mark data as deleted without actually removing it from the database describes marking data as deleted without removal.
Final Answer:
To mark data as deleted without actually removing it from the database -> Option D
Quick Check:
Soft delete = mark, not remove [OK]
Hint: Soft delete means mark deleted, not remove [OK]
Common Mistakes:
Confusing soft delete with hard delete
Thinking soft delete removes data
Assuming soft delete encrypts data
2. Which of the following is the correct way to add a soft delete flag to a MongoDB document?
easy
A. { deleted: true }
B. { isDeleted: 'yes' }
C. { deletedAt: 'no' }
D. { remove: false }
Solution
Step 1: Identify common soft delete fields
Soft delete usually uses a boolean field like 'deleted' set to true or false.
Step 2: Check options for correct boolean usage
{ deleted: true } uses { deleted: true } which is standard and correct.
Final Answer:
{ deleted: true } -> Option A
Quick Check:
Soft delete flag = boolean true [OK]
Hint: Use boolean field deleted: true for soft delete [OK]
Common Mistakes:
Using string values instead of boolean
Using unrelated field names
Confusing deletedAt with boolean flag
3. Given the collection documents: { _id: 1, name: 'Alice', deleted: false } { _id: 2, name: 'Bob', deleted: true } What will this query return? db.users.find({ deleted: false })
medium
A. [{ _id: 1, name: 'Alice', deleted: false }]
B. [{ _id: 2, name: 'Bob', deleted: true }]
C. []
D. All documents
Solution
Step 1: Understand the query filter
The query filters documents where deleted is false.
Step 2: Check documents matching filter
Only the document with _id 1 has deleted: false, so it is returned.