Add timestamps to collections.
meteor add zimme:collection-timestampable
Basic usage examples.
Posts = new Mongo.Collection('posts');
// Attach behaviour with the default options
Posts.attachBehaviour('timestampable');
// Attach behaviour with custom options
Posts.attachBehaviour('timestampable', {
createdAt: 'insertedAt',
createdBy: 'insertedBy',
updatedAt: 'modifiedAt',
updatedBy: false
});
Using CollectionBehaviours.attach
you can also attach a behaviour to multiple
collections. You can also add multiple behaviours to a collection or add
multiple behaviours to multiple collections.
Please see zimme:collection-behaviours
for more
info on attaching behaviours to collections.
Examples are using default options.
Posts.insert({
title: 'Awesome post title',
body: 'A really informative post.'
});
// Inserted document
{
"_id": "J9frYKmxaowznW3yM",
"createdAt": "2015-04-28T19:31:28.065Z",
"createdBy": "0",
"body": "A really informative post.",
"title": "Awesome post title",
}
Examples are using default options.
Posts.update({_id: 'J9frYKmxaowznW3yM'}, {
$set: {
title: 'More awesome post title'
}
});
// Updated document
{
"_id": "J9frYKmxaowznW3yM",
"createdAt": "2015-04-28T19:31:28.065Z",
"createdBy": "0",
"body": "A really informative post.",
"updatedAt": "2015-04-28T19:51:20.047Z",
"updatedBy": "0",
"title": "Awesome post title",
}
The following options can be used:
-
createdAt
: Optional. Set to'string'
to change the fields name. Set tofalse
to omit field. -
createdBy
: Optional. Set to'string'
to change the fields name. Set tofalse
to omit field. -
updatedAt
: Optional. Set to'string'
to change the fields name. Set tofalse
to omit field. -
updatedBy
: Optional. Set to'string'
to change the fields name. Set tofalse
to omit field. -
systemId
: Optional. Set to'string'
to change the id representing the system.
The global configuration for this package should be in shared code, preferably
in a lib
folder.
// Configure behaviour globally
// All collection using this behaviour will use these settings as defaults
// The settings below are the package default settings
CollectionBehaviours.configure('timestampable',{
createdAt: 'createdAt',
createdBy: 'createdBy',
updatedAt: 'updatedAt',
updatedBy: 'updatedBy',
systemId: '0'
});
- This package attaches a schema to the collection(s) if
aldeed:collection2
is used by the application. Ifaldeed:autoform
is available too, it addsaldeed:autoform
specific schema definitions