Posts

Showing posts with the label projection

How to select a single field in MongoDB?

Image
Clash Royale CLAN TAG #URR8PPP How to select a single field in MongoDB? In my MongoDB, I have a student collection with 10 records having fields name and roll . One record of this collection is: name roll { "_id" : ObjectId("53d9feff55d6b4dd1171dd9e"), "name" : "Swati", "roll" : "80", } I want to retrieve the field "roll" only for all 10 records in the collections as we would do in traditional database by using: SELECT roll FROM student I went through many blogs but all are resulting in a query which must have WHERE clause in it. For example: db.students.find({ "roll": { $gt: 70 }) The query is equivalent to: SELECT * FROM student WHERE roll > 70 My requirement is to find one field only without any condition. So, what is the query operation for that. Thanks in advance. db.students.find({"roll": { $gt: 70}) is not equivalent to SELECT roll FROM student W...