0
0
MongoDBquery~10 mins

Projection for selecting fields 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 select only the 'name' field from the 'users' collection.

MongoDB
db.users.find({}, { [1]: 1 })
Drag options to blanks, or click blank then click option'
Aemail
Bage
Cname
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 to include a field.
Selecting a field not present in the collection.
2fill in blank
medium

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

MongoDB
db.users.find({}, { [1]: 0 })
Drag options to blanks, or click blank then click option'
Apassword
Bname
Cemail
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 to exclude a field.
Trying to exclude the _id field without specifying it.
3fill in blank
hard

Fix the error in the code to select only 'name' and 'email' fields.

MongoDB
db.users.find({}, { name: 1, [1]: 1 })
Drag options to blanks, or click blank then click option'
Aemail
Baddress
Cpassword
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 for the second field.
Including fields not present in the collection.
4fill in blank
hard

Fill both blanks to exclude 'password' and 'ssn' fields from the results.

MongoDB
db.users.find({}, { [1]: 0, [2]: 0 })
Drag options to blanks, or click blank then click option'
Apassword
Bemail
Cssn
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing 1 and 0 in the same projection document.
Forgetting to exclude all sensitive fields.
5fill in blank
hard

Fill all three blanks to select 'name' and 'email' fields but exclude '_id' field.

MongoDB
db.users.find({}, { [1]: 1, [2]: 1, [3]: 0 })
Drag options to blanks, or click blank then click option'
Aname
Bemail
C_id
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to include and exclude fields at the same time incorrectly.
Not excluding '_id' when only specific fields are selected.