0
0
MongoDBquery~5 mins

Soft delete pattern in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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
Which field is commonly used to mark a document as deleted in soft delete?
Ausername
BcreatedAt
CisDeleted
Dpassword
How do you exclude soft deleted documents in a MongoDB query?
A{ isDeleted: false }
B{ isDeleted: true }
C{ deletedAt: null }
D{ isDeleted: { $ne: true } }
What is a benefit of using soft delete?
AAllows data recovery after deletion
BMakes queries faster
CReduces database size
DEncrypts data automatically
How can you permanently remove soft deleted documents?
AInsert new documents
BUse deleteMany with { isDeleted: true }
CUpdate documents to isDeleted: false
DUse findOneAndUpdate
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.