0
0
MongoDBquery~10 mins

Why delete operations need care in MongoDB - Test Your Understanding

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

Complete the code to delete all documents where the field "status" is "inactive".

MongoDB
db.collection.deleteMany({"status": [1] })
Drag options to blanks, or click blank then click option'
A"inactive"
B"active"
Ctrue
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string value.
Using the wrong field name.
Using deleteOne instead of deleteMany when multiple documents match.
2fill in blank
medium

Complete the code to delete a single document where the "username" is "guest".

MongoDB
db.users.[1]({"username": "guest"})
Drag options to blanks, or click blank then click option'
Aremove
BdeleteMany
Cdrop
DdeleteOne
Attempts:
3 left
💡 Hint
Common Mistakes
Using deleteMany and deleting more documents than intended.
Using drop which deletes the entire collection.
3fill in blank
hard

Fix the error in the delete operation to avoid deleting all documents unintentionally.

MongoDB
db.orders.deleteMany([1])
Drag options to blanks, or click blank then click option'
A{"status": "pending"}
B{}
Cnull
D[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using an empty filter and deleting the entire collection.
Passing null or an empty array as filter which causes errors.
4fill in blank
hard

Fill both blanks to delete documents where "age" is greater than 30 and "active" is false.

MongoDB
db.users.deleteMany({"age": { [1]: 30 }, "active": [2] })
Drag options to blanks, or click blank then click option'
A"$gt"
Btrue
Cfalse
D"$lt"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "$lt" instead of "$gt" for age comparison.
Using string "false" instead of boolean false.
5fill in blank
hard

Fill all three blanks to delete documents where "score" is less than 50, "passed" is false, and "grade" is "F".

MongoDB
db.results.deleteMany({"score": { [1]: 50 }, "passed": [2], "grade": [3] })
Drag options to blanks, or click blank then click option'
A"$lt"
Bfalse
C"F"
D"$gt"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "$gt" instead of "$lt" for score.
Quoting boolean false as a string.
Forgetting quotes around grade "F".