Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created January 28, 2013 17:50
Show Gist options
  • Save ynonp/4657579 to your computer and use it in GitHub Desktop.
Save ynonp/4657579 to your computer and use it in GitHub Desktop.
// lastMod.js
module.exports = exports = function lastModifiedPlugin (schema, options) {
schema.add({ lastMod: Date })
schema.pre('save', function (next) {
this.lastMod = new Date
next()
})
if (options && options.index) {
schema.path('lastMod').index(options.index)
}
}
// game-schema.js
var lastMod = require('./lastMod');
var Game = new Schema({ ... });
Game.plugin(lastMod, { index: true });
// player-schema.js
var lastMod = require('./lastMod');
var Player = new Schema({ ... });
Player.plugin(lastMod);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment