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

前端 未结 20 1573
执念已碎
执念已碎 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条回答
  •  Happy的楠姐
    2020-11-22 08:48

    I just want to add to the answers that if you want to display a field that is nested in another object, you can use the following syntax

    db.collection.find( {}, {{'object.key': true}})

    Here key is present inside the object named object

    { "_id" : ObjectId("5d2ef0702385"), "object" : { "key" : "value" } }
    
    

提交回复
热议问题