Created
January 28, 2013 17:50
-
-
Save ynonp/4657579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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