Skip to content

Instantly share code, notes, and snippets.

View pdspicer's full-sized avatar

Paul Spicer pdspicer

  • Short Hills, NJ
View GitHub Profile
@pdspicer
pdspicer / example.js
Last active December 10, 2016 17:50
Extending mongoose populated array fields with custom functionality
let mongoose = require('mongoose');
let {ObjectId, Array: SchemaArray} = mongoose.SchemaTypes;
// method for doing the path extension
function addIdsMethod (schema, pathname) {
let path = schema.paths[pathname],
defaultValue = path.defaultValue,
cast = SchemaArray.prototype.cast;
// convenience method for extending the result of an arbitrary method, applied to "this"