Assings createdAt
, createdBy
, modifiedAt
, modifiedBy
attributes to any collection in one line of code.
Installation:
meteor add goooseman:default-collection-hooks
var test = new Mongo.Collection("test");
test.defaultCollectionHooks(opts);
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.
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.