mongoose-history-log

1.0.0 • Public • Published

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 : 'test@example.net' }, function(err, doc) {
    doc.history.push({ status: "foo" });
    doc.save();
})

Package Sidebar

Install

npm i mongoose-history-log

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • weisjohn