How to select a single field for all documents in a MongoDB collection?

前端 未结 20 1278
执念已碎
执念已碎 2020-11-22 07:58

In my MongoDB, I have a student collection with 10 records having fields name and roll. One record of this collection is:

{
    \"         


        
20条回答
  •  悲哀的现实
    2020-11-22 08:31

    getting name of the student

    student-details = db.students.find({{ "roll": {$gt: 70} },{"name": 1, "_id": False})
    

    getting name & roll of the student

    student-details = db.students.find({{ "roll": {$gt: 70}},{"name": 1,"roll":1,"_id": False})
    

提交回复
热议问题