0

I seem to be constructing my mongoDB query wrong but I'm not sure how. I'd like to only get the username fields of my users database but I am getting all the fields.

My console log command (containing my query) is: console.log(JSON.stringify(Meteor.users.find({}, {_id: 0, password: 0}).fetch()));

This is the result of using the command:

[{"_id":"HF3o6oSNx2Qrg54Fc","username":"aaaa","password":"aaaapassword"},
{"_id":"H9r7qEcX7cF8kRSEf","username":"bbbb","password":"bbbbpassword"},
{"_id":"nhWZNNmBcNJuS5MFv","username":"cccc","password":"ccccpassword"}]

I have the exact same issue occurring on the server side.

My understanding from: How to select a single field in MongoDB? and http://docs.mongodb.org/manual/tutorial/project-fields-from-query-results/

is that if I used a 0 the given field would be excluded from the results.

Community
  • 1
  • 1
Bren
  • 3,516
  • 11
  • 41
  • 73

1 Answers1

1

You're usage of find is a bit off.

Meteor.users.find({}, {fields: {_id: 0, password: 0}})

Check the docs for more info.

halbgut
  • 2,368
  • 17
  • 22