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

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

    If u want to retrieve the field "roll" only for all 10 records in the collections. Then try this.

    In MongoDb :

    db.students.find( { } , { " roll " : { " $roll " })

    In Sql :

    select roll from students

提交回复
热议问题