0
0
MongoDBquery~10 mins

Subset pattern for large documents 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 project only the 'name' field from the documents.

MongoDB
db.collection.find({}, { [1]: 1 })
Drag options to blanks, or click blank then click option'
Aname
Bage
Caddress
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 to include a field
Forgetting to specify the field name
Including multiple fields when only one is needed
2fill in blank
medium

Complete the code to exclude the '_id' field from the results.

MongoDB
db.collection.find({}, { [1]: 0 })
Drag options to blanks, or click blank then click option'
Aemail
Bname
C_id
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to exclude fields by setting them to 1
Not excluding '_id' when it's not needed
Using incorrect field names
3fill in blank
hard

Fix the error in the projection to include 'name' and exclude '_id'.

MongoDB
db.collection.find({}, { [1]: 1, _id: 0 })
Drag options to blanks, or click blank then click option'
Aemail
Bname
C_id
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to include and exclude the same field
Using wrong field names
Not setting the correct values for inclusion/exclusion
4fill in blank
hard

Fill both blanks to project only 'name' and 'email' fields, excluding '_id'.

MongoDB
db.collection.find({}, { [1]: 1, [2]: 1, _id: 0 })
Drag options to blanks, or click blank then click option'
Aname
Bage
Cemail
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Including '_id' by mistake
Using 0 instead of 1 for included fields
Forgetting to include all desired fields
5fill in blank
hard

Fill all three blanks to project 'name' in uppercase, include 'email', and exclude '_id'.

MongoDB
db.collection.aggregate([{ $project: { [1]: { $toUpper: "$name" }, [2]: 1, [3]: 0 } }])
Drag options to blanks, or click blank then click option'
AnameUpper
Bemail
C_id
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original 'name' field instead of a new field
Not excluding '_id'
Incorrect field names in projection