0

According to the doc, this is how to 'Specify the Fields to Return':

collectionUsers.findOne(
  options,
  // Specify the Fields to Return
  { name: 1, id: 1 } // this does not work

  // Return All but the Excluded Fields
  // { _id: 0 } // this works
)

But it does not work as I still get _id in my result, e.g.:

{"_id":"59a53ded3a35535198135b17","id":null,"name":"jona"}

This is what I expect, e.g.:

{"id":null,"name":"jona"}

Any ideas?

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Run
  • 54,938
  • 169
  • 450
  • 748
  • You exclude instead `{ "_id": 0 }`. Don't mix include and exlude either, as it does not work with anything other than `_id`. – Neil Lunn Aug 29 '17 at 10:28
  • @NeilLunn my issue is not about `exclude` – Run Aug 29 '17 at 10:31
  • Di you even try it? Of course you didn't try because if you did you would have discovered that actually answered what you are asking. It's also [really well documented](https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/#suppress-id-field) and why I'm searching for a reasonable duplicate right now. – Neil Lunn Aug 29 '17 at 10:32
  • 1
    >> "The _id field is always included unless you explicitly exclude it." – Yury Tarabanko Aug 29 '17 at 10:35

0 Answers0