Aggregate.prototype.unwind()

Parameters
  • fields «String|Object» the field(s) to unwind, either as field names or as objects with options. If passing a string, prefixing the field name with ‘$’ is optional. If passing an object, path must start with ‘$’.
Returns:
  • «Aggregate»

Appends new custom $unwind operator(s) to this aggregate pipeline.

Note that the $unwind operator requires the path name to start with ‘$’. Mongoose will prepend ‘$’ if the specified field doesn’t start ‘$’.

Examples:

  1. aggregate.unwind("tags");
  2. aggregate.unwind("a", "b", "c");
  3. aggregate.unwind({ path: '$tags', preserveNullAndEmptyArrays: true });