Delete only one field

This is a very simple question, just a very bad brain freeze. In my aggregation, I just want to remove the "_id" field using $ project, but return the rest. However i get

"$ project requires at least one output field"

I would think that:

db.coll.aggregate( [ { $match .... }, { $project: { _id: 0 }}])

thank

+4
source share
1 answer

You need to explicitly include fields when using aggregation, either through various operations with pipelines, or through $project. There is currently no way to return all fields unless the field name is explicitly specified:

$project : {
   _id : 0,
   "Name" : 1,
   "Address" : 1
}

You can exclude _idusing the technique that you used and as shown above.

+4
source

Source: https://habr.com/ru/post/1528865/


All Articles