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:
const res = await MyModel.findOne().map(res => {
// Sets a `loadedAt` property on the doc that tells you the time the
// document was loaded.
return res == null ?
res :
Object.assign(res, { loadedAt: new Date() });
});
当前内容版权归 mongoosejs 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mongoosejs .