Query.prototype.projection()

Parameters
  • arg «Object|null»
Returns:
  • «Object» the current projection

Get/set the current projection (AKA fields). Pass null to remove the current projection.

Unlike projection(), the select() function modifies the current projection in place. This function overwrites the existing projection.

Example:

  1. const q = Model.find();
  2. q.projection(); // null
  3. q.select('a b');
  4. q.projection(); // { a: 1, b: 1 }
  5. q.projection({ c: 1 });
  6. q.projection(); // { c: 1 }
  7. q.projection(null);
  8. q.projection(); // null