Iridium plugin for automatic creation and modification timestamping
npm install iridium-timestampscreatedOn and modifiedOn properties on models defined using [Iridium][iridium], a high performance MongoDB ODM.
npm install iridium-timestamps
`Dependencies
You'll need [Iridium][iridium] to use this plugin, but other than that there are no external dependencies.Example
`javascript
var iridium = require('iridium'),
modts = require('iridium-timestamps');iridium.register(modts);
module.exports = function(db) {
var schema = {
};
var options = {
timestamps: {
createdProperty: 'createdOn',
modifiedProperty: 'modifiedOn',
now: function() { return new Date(); },
persist: true
}
};
};
`Options
- createdProperty string|false
Determines the name of the property use to store the created timestamp (default "createdOn"). If set to false, disables this property.
- modifiedProperty string|false
Determines the name of the property used to store the modified timestamp (default "modifiedOn"). If set to false, disables this property.
- now function
Allows you to specify a custom function used to set the current time data for the database (default function() { return new Date(); }).
- persist boolean
Used to prevent creation and modification timestamps from being stored in the database (default true). If you set this to false, be aware that "createdOn"` will reflect the time at which the instance was retrieved from the database.[iridium]: https://github.com/SierraSoftworks/Iridium