project based on https://github.com/goooseman/default-collection-hooks
I just customized that project with audit on update, the rest is the same
Meteor Default Collection Hooks
Assings createdAt
, createdBy
, modifiedAt
, modifiedBy
attributes to any collection in one line of code.
Getting Started
Installation:
meteor add splayerhd:default-collection-audit-hooks
Usage
var test = new Mongo.Collection("test"); test.defaultCollectionHooks(opts);
Options
opts
is an object with the following options:
createdAt
(default:true
): create acreatedAt
field with current date on object createcreatedBy
(default:true
): create acreatedBy
field with userId on object create (if there is any)modifiedAt
(default:true
): create amodifiedAt
field with current date on object updatemodifiedBy
(defulat:true
): create amodifiedBy
field with userId on object update (if there is any)
If you do not pass a options object, it will use the defaults. You can pass only the options you want to modify.
Examples
var test = new Mongo.Collection("test"); test.defaultCollectionHooks();
Will create createdAt
, createdBy
on object create and modifiedAt
, modifiedBy
attributes on object update.
var test = new Mongo.Collection("test"); test.defaultCollectionHooks({ modifiedAt: false, modifiedBy: false });
Will create createdAt
, createdBy
on object create, and do nothing on object update.