0
0
MongoDBquery~10 mins

Soft delete pattern in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to mark a document as deleted by setting the 'deleted' field to true.

MongoDB
db.users.updateOne({ _id: userId }, { $set: { deleted: [1] } })
Drag options to blanks, or click blank then click option'
Aundefined
Bfalse
Cnull
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Setting 'deleted' to false instead of true.
Using null or undefined which do not indicate deletion.
2fill in blank
medium

Complete the query to find only documents that are not soft deleted.

MongoDB
db.users.find({ deleted: [1] })
Drag options to blanks, or click blank then click option'
Atrue
Bnull
Cfalse
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Searching for deleted: true which returns deleted documents.
Using null or empty object which does not filter correctly.
3fill in blank
hard

Fix the error in the update query to soft delete a document by setting 'deleted' to true.

MongoDB
db.users.updateOne({ _id: userId }, { $set: { deleted: [1] } })
Drag options to blanks, or click blank then click option'
Anull
Btrue
C1
D"true"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "true" as a string instead of boolean true.
Using 1 which is a number, not a boolean.
4fill in blank
hard

Fill both blanks to query active users and sort them by creation date descending.

MongoDB
db.users.find({ deleted: [1] }).sort({ createdAt: [2] })
Drag options to blanks, or click blank then click option'
Afalse
Btrue
C-1
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using deleted: true to find deleted users.
Sorting ascending (1) instead of descending (-1).
5fill in blank
hard

Fill all three blanks to update a document's 'deleted' status, set 'deletedAt' timestamp, and exclude deleted documents in a query.

MongoDB
db.users.updateOne({ _id: userId }, { $set: { deleted: [1], deletedAt: [2] } });
db.users.find({ deleted: [3] })
Drag options to blanks, or click blank then click option'
Atrue
Bnew Date()
Cfalse
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Not setting deletedAt timestamp.
Querying for deleted: true instead of false.