How to hide _id from Aggregation?

From mongodb docs

You can $project the results to exclude the _id - is this what you mean?

http://docs.mongodb.org/manual/reference/aggregation/#pipeline

Note The _id field is always included by default. You may explicitly exclude _id as follows:

db.article.aggregate(
    { $project : {
        _id : 0 ,
        title : 1 ,
        author : 1
    }}
);

From you're example, the first operation in the pipeline would be to exclude the _id and include the other attribs.


Starting Mongo 4.2, the $unset aggregation operator can be used as an alternative syntax for $project when used to only drop fields:

// { _id: "1sd", pup: [{ avt: { fto: "whatever"} }] }
// { _id: "d3r", pup: [{ avt: { fto: "whatever else"} }] }
db.collection.aggregate({ $unset: ["_id"] })
// { pup: [{ avt: { fto: "whatever" } } ] }
// { pup: [{ avt: { fto: "whatever else" } } ] }