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

前端 未结 20 1245
执念已碎
执念已碎 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:49

    I think mattingly890 has the correct answer , here is another example along with the pattern/commmand

    db.collection.find( {}, {your_key:1, _id:0})

    enter image description here

    0 讨论(0)
  • 2020-11-22 08:50

    Try the following query:

    db.student.find({}, {roll: 1, _id: 0}).pretty();
    

    Hope this helps!!

    0 讨论(0)
提交回复
热议问题