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

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

    This works for me,

    db.student.find({},{"roll":1})
    

    no condition in where clause i.e., inside first curly braces. inside next curly braces: list of projection field names to be needed in the result and 1 indicates particular field is the part of the query result

提交回复
热议问题