Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 to include a field.
Selecting a field not present in the collection.
✗ Incorrect
To select only the 'name' field, you specify it with a value of 1 in the projection document.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 to exclude a field.
Trying to exclude the _id field without specifying it.
✗ Incorrect
Setting a field to 0 in the projection excludes it from the results.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 for the second field.
Including fields not present in the collection.
✗ Incorrect
To select multiple fields, list each with a value of 1 in the projection document.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing 1 and 0 in the same projection document.
Forgetting to exclude all sensitive fields.
✗ Incorrect
To exclude multiple fields, list each with 0 in the projection document.
5fill in blank
hardFill 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'
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.
✗ Incorrect
To include fields, set them to 1; to exclude '_id', set it to 0.