Articles → MONGODB → $Project Aggregation Stage In Mongodb
$Project Aggregation Stage In Mongodb
Purpose
- Including or excluding fields
- Adding new fields
- Modify existing fields
Example
db.Employees.aggregate([
{
$project: {
_id:1, // Include
fullname : {$concat: ["$firstname"," ", "$lastname"]},// adding a new field
EmployeeAge: "$age" // Rename
}
}
])
Output