Mongoose plugin to store audit information like userAgent, ip, country, etc...
MIT License
Mongoose plugin to store audit information like userAgent, ip, country, etc...
This plugin simply adds the following fields:
Where:
Note: deletedBy and deletedFrom are only useful if combined with mongoose-delete plugin.
$ npm install mongoose-audit --save
BlogPost.plugin(mongooseAudit, { userModel: 'Author' });
On create:
const post = new BlogPost({});
post.createdBy = currentUserId;
post.createdFrom = {{ ip, userAgent, country };
await post.save();
On update:
post.set();
post.updatedBy = currentUserId;
post.updatedFrom = {{ ip, userAgent, country };
await post.save();
On delete (only useful if combined with mongoose-delete plugin)
post.deletedBy = currentUserId;
post.deletedFrom = {{ ip, userAgent, country };
await post.save();
await post.delete();