0
0
MongoDBquery~10 mins

$project stage for shaping output 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 include only the "name" field in the output documents.

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

Complete the code to exclude the "password" field from the output documents.

MongoDB
db.collection.aggregate([{ $project: { [1]: 0 } }])
Drag options to blanks, or click blank then click option'
Apassword
Busername
Cemail
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 to exclude a field.
Excluding the wrong field.
Mixing inclusion and exclusion in the same $project stage.
3fill in blank
hard

Fix the error in the $project stage to rename the "firstName" field to "name" in the output.

MongoDB
db.collection.aggregate([{ $project: { name: "$[1]" } }])
Drag options to blanks, or click blank then click option'
AlastName
BfirstName
CfullName
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the $ sign before the original field name.
Using the new field name instead of the original after the $ sign.
Not using quotes around the original field name.
4fill in blank
hard

Fill both blanks to include "name" and exclude "_id" in the output documents.

MongoDB
db.collection.aggregate([{ $project: { [1]: 1, [2]: 0 } }])
Drag options to blanks, or click blank then click option'
Aname
B_id
Cage
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to include and exclude the same field.
Forgetting to exclude _id when including other fields.
Using wrong field names.
5fill in blank
hard

Fill all three blanks to rename "firstName" to "name", include "age", and exclude "_id" in the output.

MongoDB
db.collection.aggregate([{ $project: { [1]: "$firstName", [2]: 1, [3]: 0 } }])
Drag options to blanks, or click blank then click option'
Aname
Bage
C_id
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Not using $ before original field name when renaming.
Mixing inclusion and exclusion incorrectly.
Forgetting to exclude _id.