I am creating a mongoose pre save hook, I want to know the name of the model/collection, which I am saving in the pre save hook. From which variable can I get it.
module.exports = exports = function lastModifiedPlugin (schema, options) {
schema.pre('save', function (next) {
var self = this;
self.constructor.findOne({ _id: self._id }, function (err, launch){
console.log(" model " + self.mongooseCollection);
console.log(Object.getOwnPropertyNames(this));
console.log(Object.getOwnPropertyNames(schema));
next()
});
})
if (options && options.index) {
schema.path('lastMod').index(options.index)
}
}
I tried to explore functions and properties of this
and schema
variable but could not got the name od model being saved.