mongo-created-modified

2.0.2 • Public • Published

mongo-created-modified

Decorator for a mongo collection that add created and modified timestamp to the documents.

A created-modified document will have the properties createdDate sand lastModifiedDate.

{
  createdDate: new Date(),
  lastModifiedDate: new Date(),
  data: ...
}

Usage:

var mongoCreatedModified = require('mongo-created-modified');
 
mongodb.Db.connect(connection, function(err, db){
  if(err) throw err;
 
  database.collection('createdModifiedCollection', function (err, col) {
    if(err) throw err;
 
    var createdModifiedCollection = mongoCreatedModified(col);
 
    createdModifiedCollection.insert({a: 1}, function(err, doc) {
      if(err) throw err;
 
      createdModifiedCollection.findAnsModify({a: 1}, [], {a: 2},function (err, doc) {
        if(err) throw err;
 
        // returns document with createdDate and lastModifiedDate
        console.log(doc);
      });
    })
  });
});

Readme

Keywords

none

Package Sidebar

Install

npm i mongo-created-modified

Weekly Downloads

5

Version

2.0.2

License

none

Unpacked Size

63.7 kB

Total Files

19

Last publish

Collaborators

  • mujichok