v2.0.2Published 6 days ago


Preliminary notes

This package is a fork from zimme:collection-timestampable v 1.0.9:

  • because I use it and like it (that's fine ;))
  • unfortunately, it seems no more maintained
  • so make it compatible with Meteor 2.x and incoming Meteor 3.x.

It also now features upserts management.

What is it ?

This Meteor package adds a timestampable behaviour to any Mongo collection.


This Meteor package is installable with the usual command:

    meteor add pwix:collection-timestampable


Basic usage examples.


1    Posts = new Mongo.Collection( 'posts' );
3    // Attach behaviour with the default options
4    Posts.attachBehaviour( 'timestampable' );
6    // Attach behaviour with custom options
7    Posts.attachBehaviour( 'timestampable', {
8        createdAt: 'insertedAt',
9        createdBy: 'insertedBy',
10        updatedAt: 'modifiedAt',
11        updatedBy: false
12    });

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 pwix:collection-behaviours for more info on attaching behaviours to collections.


Examples are using default options.

1    Posts.insert({
2        title: 'Awesome post title',
3        body: 'A really informative post.'
4    });
6    // Inserted document
7    {
8        "_id": "J9frYKmxaowznW3yM",
9        "createdAt": "2015-04-28T19:31:28.065Z",
10        "createdBy": "0",
11        "body": "A really informative post.",
12        "title": "Awesome post title",
13    }


Examples are using default options.

1    Posts.update({_id: 'J9frYKmxaowznW3yM'}, {
2        $set: {
3            title: 'More awesome post title'
4        }
5    });
7    // Updated document
8    {
9        "_id": "J9frYKmxaowznW3yM",
10        "createdAt": "2015-04-28T19:31:28.065Z",
11        "createdBy": "0",
12        "body": "A really informative post.",
13        "updatedAt": "2015-04-28T19:51:20.047Z",
14        "updatedBy": "0",
15        "title": "Awesome post title",
16    }



The package's behavior can be configured through a call to the CollectionBehaviours.configure() method, with just a single javascript object argument, which itself should only contains the options you want override.

1    // Configure behaviour globally
2    // All collection using this behaviour will use these settings as defaults
3    // The settings below are the package default settings
4    CollectionBehaviours.configure( 'timestampable', {
5        createdAt: 'createdAt',
6        createdBy: 'createdBy',
7        updatedAt: 'updatedAt',
8        updatedBy: 'updatedBy',
9        systemId: '0'
10    });

Please note that CollectionBehaviours.configure() method should be called in the same terms both in client and server sides.

Remind too that Meteor packages are instanciated at application level. They are so only configurable once, or, in other words, only one instance has to be or can be configured. Addtionnal calls to CollectionBehaviours.configure() will just override the previous one. You have been warned: only the application should configure a package.


The following options can be used:

  • createdAt: Optional. Set to 'string' to change the fields name. Set to false to omit field.

  • createdBy: Optional. Set to 'string' to change the fields name. Set to false to omit field.

  • updatedAt: Optional. Set to 'string' to change the fields name. Set to false to omit field.

  • updatedBy: Optional. Set to 'string' to change the fields name. Set to false to omit field.

  • systemId: Optional. Set to 'string' to change the id representing the system.


This package attaches a schema to the collection(s) if aldeed:collection2 is used by the application. If aldeed:autoform is available too, it adds aldeed:autoform specific schema definitions.

NPM peer dependencies

None at the moment.


None at the moment.

Cookies and comparable technologies

None at the moment.

Issues & help

In case of support or error, please report your issue request to our Issues tracker.