Challenge - 5 Problems
Projection Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Projection to include specific fields
Given a MongoDB collection users with documents containing
Assume the collection has:
name, age, and email, what will be the output of this query?db.users.find({}, {name: 1, email: 1, _id: 0})Assume the collection has:
{"name": "Alice", "age": 30, "email": "alice@example.com"}{"name": "Bob", "age": 25, "email": "bob@example.com"}MongoDB
db.users.find({}, {name: 1, email: 1, _id: 0})Attempts:
2 left
💡 Hint
Projection includes only the fields set to 1 and excludes _id when set to 0.
✗ Incorrect
The projection specifies to include only 'name' and 'email' fields and exclude '_id'. So the output documents contain only those fields.
❓ query_result
intermediate2:00remaining
Projection excluding fields
What will be the result of this MongoDB query?
Given documents:
db.products.find({}, {description: 0, _id: 0})Given documents:
{"name": "Pen", "price": 1.5, "description": "Blue ink pen"}{"name": "Notebook", "price": 3.0, "description": "200 pages"}MongoDB
db.products.find({}, {description: 0, _id: 0})Attempts:
2 left
💡 Hint
Setting a field to 0 excludes it from the result.
✗ Incorrect
The projection excludes 'description' and '_id', so only 'name' and 'price' remain in the output.
📝 Syntax
advanced2:00remaining
Identify the invalid projection syntax
Which of the following MongoDB queries has invalid projection syntax and will cause an error?
Attempts:
2 left
💡 Hint
You cannot mix inclusion (1) and exclusion (0) in the same projection except for _id.
✗ Incorrect
Option D mixes inclusion (item, quantity, _id) and exclusion (price), which is invalid and causes an error.
❓ optimization
advanced2:00remaining
Optimizing data transfer with projection
You have a large collection
logs with documents containing many fields. You only need the timestamp and level fields for your report. Which query best reduces data transfer?Attempts:
2 left
💡 Hint
Exclude _id if you don't need it to reduce data size further.
✗ Incorrect
Option A includes only needed fields and excludes _id, minimizing data sent over the network.
🧠 Conceptual
expert3:00remaining
Understanding projection behavior with nested fields
Consider documents in
What will be the output of this query?
employees collection with nested address field:{"name": "John", "address": {"city": "NY", "zip": "10001"}, "age": 28}What will be the output of this query?
db.employees.find({}, {"address.city": 1, _id: 0})MongoDB
db.employees.find({}, {"address.city": 1, _id: 0})Attempts:
2 left
💡 Hint
Projection on nested fields returns the parent object with only the specified nested fields.
✗ Incorrect
The query returns the 'address' object but only with the 'city' field included, excluding other fields and _id.