0

I know this is a very basic question but I have done hours of research and I can't find it anywhere so maybe it's also useful for other people.

I just downloaded MongoDB Compass because I'm trying to export all username from my account collection and there's no way I can create a query that returns only the username field.

How can I, with MongoDB, get all the values of a specific field?

Thank you

Joan Cardona
  • 3,463
  • 2
  • 25
  • 43

2 Answers2

2

Use Projection.

Where you can add or remove Field in results of data.

Try

db.collection.find({}, { user_name : 1})

Where 1 is true and 0 is false.

Developer
  • 3,309
  • 2
  • 19
  • 23
0

This will return only user_name field from all documents

db.collection.find({}, {"_id": 0, "user_name": 1})
Dexter
  • 831
  • 8
  • 17