Decorator for a mongo collection that add created and modified timestamp to the documents.
{
createdDate: new Date(),
lastModifiedDate: new Date(),
data: ...
}
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;
console.log(doc);
});
})
});
});