Skip to content

Instantly share code, notes, and snippets.

@ADelRosarioH
Forked from ynonp/lastmod.js
Created May 14, 2014 14:40
Show Gist options
  • Save ADelRosarioH/3349075d33351daec755 to your computer and use it in GitHub Desktop.
Save ADelRosarioH/3349075d33351daec755 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