10

db.users.find({}) returns all the users with all the field.

How to write a request that would return only the 'email' field for all user ?

Blastfurnace
  • 18,411
  • 56
  • 55
  • 70
François Richard
  • 6,817
  • 10
  • 43
  • 78

1 Answers1

38

Please take a look at the documentation. You will notice that find has an optional second parameter called "projection". This parameter is used to state which fields you want. To get only the field named "email", use this projection:

db.users.find({}, { _id: 0, email: 1 })
Philipp
  • 67,764
  • 9
  • 118
  • 153
  • yep, I've read (too quickly) this part of the doc, trying things like that db.users.find({}, {email:*}) , should have read more seriously =) thanks – François Richard Nov 29 '15 at 11:09
  • when add _id: 0 or _id: false, it also return _id: null How can we eliminate _id ni from the result get back? – van le Apr 15 '19 at 14:53