Aggregate.prototype.project()

Parameters
  • arg «Object|String» field specification
Returns:
  • «Aggregate»

Appends a new $project operator to this aggregate pipeline.

Mongoose query selection syntax is also supported.

Examples:

  1. // include a, include b, exclude _id
  2. aggregate.project("a b -_id");
  3. // or you may use object notation, useful when
  4. // you have keys already prefixed with a "-"
  5. aggregate.project({a: 1, b: 1, _id: 0});
  6. // reshaping documents
  7. aggregate.project({
  8. newField: '$b.nested'
  9. , plusTen: { $add: ['$val', 10]}
  10. , sub: {
  11. name: '$a'
  12. }
  13. })
  14. // etc
  15. aggregate.project({ salary_k: { $divide: [ "$salary", 1000 ] } });