oute-services-mongoose-audit-sdk
v0.0.10
Published
- Initialization And Uses - If any transaction making multiple doc modification then you can use txn_id will be same for all - In this package we support bellow hooks
Downloads
3
Readme
This module Used for mongoose collection audit
- Initialization And Uses
- If any transaction making multiple doc modification then you can use txn_id will be same for all
- In this package we support bellow hooks
"save"
"update"
"updateOne"
"updateMany"
"remove"
"deleteOne"
"deleteMany"
mongooseAuditOptions = {
indexes: [{"created_at": -1, "document._id": 1}], //this block used for creating index on audit
diff_only: false, //Use for storing only diff object
excluded_keys: [], //Any key needs to be excluded from document
connection: mongoose //Your existing mongoose object or new mongoose
custom_collection_name: undefined //Custom collection name
metadata: [ //To maintain custom keys as per your requirement
{key: "x", value: "x.y"}
{key: "y", value: (old_obj, new_obj)=> return "x.y"}
{key: "z", value: (old_obj, new_obj, callback)=> return callback(null, "x.y.z")}
]
}
mongooseAudit = require("oute-services-mongoose-audit-sdk")
testSchema = mongoose.Schema({name: {type: String required: true}})
testSchema.plugin(mongooseAudit, mongooseAuditOptions)
Test = mongoose.model "test", testSchema, "test"
//to get audit model, this will have all mongoose functions
AuditModel = Test.getAuditModel()
//to clear all audit data
await Test.clearAuditData()