Aggregates with project stage

Hello Hélène Ortiz,

The group stage returns documents with only the _id field. If you notice carefully, the _id field is a sub-document with the four fields (ctype, pname, …). So, you need to project, for example, _id.ctype as ctype (same for the remaining 3 fields). The following code does that:

Aggregates.project(
    Projections.fields(
        Projections.computed("ctype", "$_id.ctype"), 
        Projections.computed("pname", "$_id.pname"),
        Projections.computed("ctype", "$_id.ctype"), 
        Projections.computed("pname", "$_id.pname"),
        Projections.excludeId()
    )
)