Introduction
Projection helps you choose only the information you want from your data, making it easier to see and use.
Jump into concepts and practice - no test required
db.collection.find(query, { field1: 1, field2: 1, _id: 0 })db.users.find({}, { name: 1, email: 1, _id: 0 })db.books.find({ author: "Alice" }, { title: 1, _id: 1 })db.orders.find({}, { _id: 0, product: 1, quantity: 1 })db.students.insertMany([
{ name: "John", age: 20, grade: "A" },
{ name: "Jane", age: 22, grade: "B" },
{ name: "Mike", age: 21, grade: "A" }
])
// Find all students but show only name and grade, hide _id
db.students.find({}, { name: 1, grade: 1, _id: 0 })name and age fields in a MongoDB find query?{ _id: 1, name: "Alice", age: 25, city: "NY" }{ _id: 2, name: "Bob", age: 30, city: "LA" }db.collection.find({}, { name: 1, city: 1 })?_id field unless explicitly excluded.name and city fields with 1, so these fields plus _id will appear.password field?db.users.find({}, { password: 1 })password: 1, so it includes the password field (and _id), not excludes it._id and password fields while including all others. Which projection is correct?_id and password, set both to 0 in the projection.