How to hide _id from Aggregation?

后端 未结 4 1136
广开言路
广开言路 2020-12-30 21:25

I\'ve this query:

produits = yield motor.Op(db.users.aggregate, [{\"$unwind\":\"$pup\"},{\"$match\":{\"pup.spec.np\":nomp}}, {\"$group\":{\"_id\":\"$pup.spec         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 22:00

    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.

提交回复
热议问题