Complete the code to include only the "name" field in the output documents.
db.collection.aggregate([{ $project: { [1]: 1 } }])The $project stage shapes the output by including only the specified fields. Here, including name with value 1 means only the name field will appear in the output.
Complete the code to exclude the "password" field from the output documents.
db.collection.aggregate([{ $project: { [1]: 0 } }])Setting a field to 0 in $project excludes it from the output. Here, excluding password hides it from the results.
Fix the error in the $project stage to rename the "firstName" field to "name" in the output.
db.collection.aggregate([{ $project: { name: "$[1]" } }])To rename a field in $project, use the syntax newField: "$oldField". Here, name: "$firstName" renames firstName to name.
Fill both blanks to include "name" and exclude "_id" in the output documents.
db.collection.aggregate([{ $project: { [1]: 1, [2]: 0 } }])Including name: 1 shows the name field, and excluding _id: 0 hides the default MongoDB ID field from output.
Fill all three blanks to rename "firstName" to "name", include "age", and exclude "_id" in the output.
db.collection.aggregate([{ $project: { [1]: "$firstName", [2]: 1, [3]: 0 } }])This $project stage renames firstName to name, includes the age field, and excludes the _id field from the output.