Query.prototype.map()

Parameters
  • fn «Function» function to run to transform the query result
Returns:
  • «Query» this

Runs a function fn and treats the return value of fn as the new value for the query to resolve to.

Any functions you pass to map() will run after any post hooks.

Example:

  1. const res = await MyModel.findOne().map(res => {
  2. // Sets a `loadedAt` property on the doc that tells you the time the
  3. // document was loaded.
  4. return res == null ?
  5. res :
  6. Object.assign(res, { loadedAt: new Date() });
  7. });