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 ?

1
  • Use the find projection parameter - db.users.find({}, {email:1, _id:0}) Commented Nov 29, 2015 at 11:04

1 Answer 1

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 })
Sign up to request clarification or add additional context in comments.

2 Comments

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
when add _id: 0 or _id: false, it also return _id: null How can we eliminate _id ni from the result get back?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.