In my MongoDB, I have a student collection with 10 records having fields name
and roll
. One record of this collection is:
{
\"
db..find({}, {field1: , field2: ...})
In your example, you can do something like:
db.students.find({}, {"roll":true, "_id":false})
Projection
The projection parameter determines which fields are returned in the matching documents. The projection parameter takes a document of the following form:
{ field1: , field2: ... }
The
can be any of the following:
1 or true to include the field in the return documents.
0 or false to exclude the field.
NOTE
For the _id field, you do not have to explicitly specify _id: 1 to return the _id field. The find() method always returns the _id field unless you specify _id: 0 to suppress the field.
READ MORE