Mongoose plugin that adds createdAt, updatedAt, and deletedAt auto-assigned date properties
Simple plugin for Mongoose which adds
deletedAt date attributes
that get auto-assigned to the most recent create/update timestamp. Currently, you need to manually manage
npm install --save mongoose-stamp
var stampIt = require'mongoose-stamp';var userSchema =username: String;UserSchemapluginstampIt;mongoosemodel'User' userSchema;var User = mongoosemodel'User' userSchema
The User model will now have
updatedAt properties, which get
automatically generated and updated when you save your document. mongoose-stamp will also add support for developers setting the
deletedAt property on a model instead of removing it. However, due to limitations of the mongoose plugin architecture, we are unable to automaticlly add support for the
deletedAt property. mongoose-stamp requires developers to maintain the
deletedAt property themselves if they use it.
var user = username: 'Prince';usersaveconsole.logusercreatedAt; // Should be approximately nowconsole.logusercreatedAt === userupdatedAt; // true// Wait 1 second and then update the usersetTimeoutuserusername = 'Symbol';usersaveconsole.loguserupdatedAt; // Should be approximately createdAt + 1 secondconsole.logusercreatedAt < userupdatedAt; // true;1000;;
(The MIT License)
Copyright (c) 2013-2016 Tarun Chaudhry <firstname.lastname@example.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.