Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weisjohn/mongoose-history-log
add a collection of events to a schema
https://github.com/weisjohn/mongoose-history-log
Last synced: about 1 month ago
JSON representation
add a collection of events to a schema
- Host: GitHub
- URL: https://github.com/weisjohn/mongoose-history-log
- Owner: weisjohn
- License: mit
- Created: 2015-07-23T03:20:35.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-07-23T03:48:14.000Z (over 9 years ago)
- Last Synced: 2024-10-29T15:41:15.567Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/mongoose-history-log
- Size: 129 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongoose-history-log
add a collection of events to a schema
### usage
schema setup:
```javascript
var mongoose = require('mongoose');
var mhl = require('mongoose-history-log');var schema = new mongoose.Schema({ name: String });
mhl(schema);
```This adds a `history` property to the schema which is an array of objects:
```javascript
[{
time: { type: Date, default: Date.now },
status: String,
meta: {}
}]
```The `meta` property allows you to attach an arbitrartily complex object onto the `history` element. When saving the document for the first time, it will automatically add an `{ status : "created" }` record with the current time.
Adding other events:
```javascript
var user = mongoosel.model('user');user.findOne({ email : '[email protected]' }, function(err, doc) {
doc.history.push({ status: "foo" });
doc.save();
})
```