0
0
MongoDBquery~20 mins

Excluding fields from results in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MongoDB Projection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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})
Adb.users.find({}, {email: 0})
Bdb.users.find({}, {email: 1})
Cdb.users.find({}, {email: false})
Ddb.users.find({}, {email: null})
Attempts:
2 left
💡 Hint
Use 0 to exclude a field in the projection document.
query_result
intermediate
2: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})
Adb.accounts.find({}, {password: null, ssn: null})
Bdb.accounts.find({}, {password: 1, ssn: 1})
Cdb.accounts.find({}, {password: false, ssn: false})
Ddb.accounts.find({}, {password: 0, ssn: 0})
Attempts:
2 left
💡 Hint
Exclude multiple fields by setting each to 0 in the projection.
📝 Syntax
advanced
2:00remaining
Identify the invalid MongoDB projection syntax
Which of the following MongoDB queries will cause a syntax error due to incorrect projection?
Adb.products.find({}, {price: false, name: 0})
Bdb.products.find({}, {price: 1, name: 0})
Cdb.products.find({}, {price: 0, name: 1})
Ddb.products.find({}, {price: 0, name: 0})
Attempts:
2 left
💡 Hint
Projection values must be 0 or 1, not false.
🧠 Conceptual
advanced
2: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}?
AMongoDB excludes both fields regardless of the values.
BMongoDB excludes field1 and includes field2 without error.
CMongoDB throws an error because you cannot mix inclusion and exclusion except for _id.
DMongoDB ignores the exclusion and includes all fields.
Attempts:
2 left
💡 Hint
MongoDB projection rules restrict mixing inclusion and exclusion.
optimization
expert
3: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?
Adb.videos.find({}, {videoData: 1})
Bdb.videos.find({}, {videoData: 0})
Cdb.videos.find({}, {videoData: null})
Ddb.videos.find({}, {videoData: false})
Attempts:
2 left
💡 Hint
Exclude large fields to reduce data transfer and improve speed.