using ONLY aggregation (i.e. being inside the pipeline ) and $$ROOT create a cursor containing all fields of the model (automatically) + computed fields. Of course, all the fields of the model can be listed by pens. But, since one script will do the work with different collections, you need the fields to be inserted automatically.
Option 1 (will not work)
Коллекция.aggregate([{ $project:{ fields:"$$ROOT", computedFields: { id:"$_id" } } }], callback) It will not work, as it generates documents of the following type: {fields:{поля объекта}, computedFields:{id:104}}
It is necessary that it turned out:{поле1:знач1, поле2:знач2, ... id:104} , where field1, field2, ... are fields taken automatically from the collection model.
Option 2 (will not work):
var obj= {поле1:1, поле2:1, ... id:"$_id"} Коллекция.aggregate([{ $project:obj }], callback)