mongo-created-modified
v2.0.2
Published
Mongo collection decorator that add created and modified timestamp on documents
Downloads
3
Readme
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);
});
})
});
});