Challenge - 5 Problems
MongoDB Projection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Excluding a single field from MongoDB query results
Given a collection
users with documents containing name, age, and email, which query excludes the email field from the results?MongoDB
db.users.find({}, {email: 0})Attempts:
2 left
💡 Hint
Use 0 to exclude a field in the projection document.
✗ Incorrect
In MongoDB, setting a field to 0 in the projection excludes it from the results. Setting it to 1 includes it. Using false or null is invalid syntax.
❓ query_result
intermediate2:00remaining
Excluding multiple fields in MongoDB query results
Which query excludes both
password and ssn fields from the accounts collection results?MongoDB
db.accounts.find({}, {password: 0, ssn: 0})Attempts:
2 left
💡 Hint
Exclude multiple fields by setting each to 0 in the projection.
✗ Incorrect
Setting multiple fields to 0 in the projection excludes them all from the results. Including them with 1 would only show those fields.
📝 Syntax
advanced2:00remaining
Identify the invalid MongoDB projection syntax
Which of the following MongoDB queries will cause a syntax error due to incorrect projection?
Attempts:
2 left
💡 Hint
Projection values must be 0 or 1, not false.
✗ Incorrect
MongoDB projection only accepts 0 or 1 to exclude or include fields. Using false causes a syntax error.
🧠 Conceptual
advanced2:00remaining
Understanding exclusion and inclusion in MongoDB projections
What happens if you try to exclude one field and include another in the same MongoDB projection, like
{field1: 0, field2: 1}?Attempts:
2 left
💡 Hint
MongoDB projection rules restrict mixing inclusion and exclusion.
✗ Incorrect
MongoDB does not allow mixing inclusion and exclusion in the same projection except for the _id field. Doing so causes an error.
❓ optimization
expert3:00remaining
Optimizing MongoDB queries by excluding large fields
You have a collection
videos where each document has a large videoData field. To improve query speed when listing videos, which projection is best?Attempts:
2 left
💡 Hint
Exclude large fields to reduce data transfer and improve speed.
✗ Incorrect
Excluding the large videoData field with videoData: 0 reduces the amount of data sent, improving query speed. Including it or using invalid values does not help.