比如employees集合,我们只想显示 empid,name
可以按下面显示:
db.employees.find({},{empid:1,name:1})
> db.employees.find({},{empid:1,name:1});
{ "_id" : ObjectId("64a8e771c531db7498ca2081"), "empid" : 100, "name" : "mhan" }
{ "_id" : ObjectId("64a8e795c531db7498ca2082"), "empid" : 101, "name" : "liuzy" }
{ "_id" : ObjectId("64a8e7e3c531db7498ca2083"), "empid" : 102, "name" : "wjia" }
{ "_id" : ObjectId("64a8e841c531db7498ca2084"), "empid" : 103, "name" : "zyin" }
不想显示:_id
> db.employees.find({},{"_id":0,empid:1,name:1});
{ "empid" : 100, "name" : "mhan" }
{ "empid" : 101, "name" : "liuzy" }
{ "empid" : 102, "name" : "wjia" }
{ "empid" : 103, "name" : "zyin" }
>
|