Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ajpocus/mongoose-concrete-timestamps
Save concrete, non-virtual timestamps on your Mongoose models.
https://github.com/ajpocus/mongoose-concrete-timestamps
Last synced: about 1 month ago
JSON representation
Save concrete, non-virtual timestamps on your Mongoose models.
- Host: GitHub
- URL: https://github.com/ajpocus/mongoose-concrete-timestamps
- Owner: ajpocus
- Created: 2013-08-03T01:17:44.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-13T20:21:59.000Z (almost 10 years ago)
- Last Synced: 2024-11-18T02:41:02.380Z (2 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mongoose-concrete-timestamps
Saves visible, non-virtual timestamps to Mongoose models. Intended as a replacement for mongoose-timestamp.## Intro
You can install mongoose-concrete-timestamps with npm:
npm install mongoose-concrete-timestamps
This module serves a simple purpose: write a createdAt timestamp on the first save(), and update the updatedAt timestamp on each save().
## Usage
Using this module is super-simple. Just require the module:
var timestamps = require('mongoose-concrete-timestamps');
And plug it into your schema:
var userSchema = new mongoose.Schema({ name: String });
userSchema.plugin(timestamps);
var User = mongoose.model('User', userSchema);var user = new User({ name: "Foo" });
user.save(function (err, user) {
// user.createdAt will be set to Date.now, at the time of the save() call.
// The same goes for user.updatedAt, except it's updated on each save().
});## Testing
To run the tests for this module, make sure you have `mocha` installed:
npm install -g mocha
Once installed, you can run the tests by invoking `mocha` from the project's root.