MongoDB Tutorial 0/120 lessons ~6 min read Lesson 37
Projection
Projection shapes the returned documents — picking fields, slicing arrays, or computing values.
Course progress0%
Focus
4 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Projection shapes the returned documents — picking fields, slicing arrays, or computing values. Smaller payloads = faster network = happier UI.
Syntax reference
js
db.users.find({}, { name: 1, email: 1, _id: 0 });// Array slicedb.posts.find({}, { comments: { $slice: 5 } });// Computed (aggregation)db.users.aggregate([{ $project: { fullName: { $concat: ["$first"," ","$last"] } } }]);
Real-world use
List endpoints should always project — never return the full document for a row in a table.
Best practices
- Project explicitly; don't rely on
SELECT *habits. - Combine with covering indexes for zero-fetch queries.
Ready to mark this lesson complete?Track your journey across the entire course.