1

I don't usually want or need the "_id" field to be returned in my queries. So, for each query, I have to set:

{ $projection: "_id": 0 }

Is it possible to set this value globally so that any query executed will not include the "_id" field?

Fernando Vega
  • 525
  • 4
  • 13
  • No there's no global projection option in MongoDB. Note that the `_id` field can be customized, as long as the values are unique across that collection. Why not utilize this fact and use the `_id` to store something meaningful? – kevinadi Jul 19 '18 at 23:53

1 Answers1

0

In MongoDB you can't use any global projection if you don't want a _id field you can set {_id:0} in projection. If you use aggregation you can project {"$project" : {"_id" : 0,...}} your fields in an initial pipeline stage. because MongoDB every pipeline input is depending on the previous pipeline out. aggregation pipeline stages , $project

Senthur Deva
  • 737
  • 4
  • 12