mongoose-history-log
v1.0.0
Published
add a collection of events to a schema
Downloads
10
Maintainers
Readme
mongoose-history-log
add a collection of events to a schema
usage
schema setup:
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:
[{
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:
var user = mongoosel.model('user');
user.findOne({ email : '[email protected]' }, function(err, doc) {
doc.history.push({ status: "foo" });
doc.save();
})