Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created August 24, 2011 12:07
Show Gist options
  • Save aheckmann/1167922 to your computer and use it in GitHub Desktop.
Save aheckmann/1167922 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose')
var Schema = mongoose.Schema
console.error('mongoose version %s', mongoose.version);
var s = new Schema({ name: String })
s.pre('init', function (next, doc) {
console.error('pre', arguments);
var changed = { name: doc.first + ' ' + doc.last };
next(changed);
});
var P = mongoose.model('Person', s);
var p = new P;
p.init({ first: 'aaron', last: 'heckmann'});
console.error('p is %j', p);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment