0

I'm using nodejs with mongodb and need to log users actions (who does what ).

To do so, I'm using pre middleware and log4js to write in file, it's something like this :

 var userSchema = new Schema(..);
 userSchema.pre('save', function(next) {
  log.TRACE(req.user.id ...);
 next();
 });

All I need now is to pass a param(req.user.id) from user.save() or user.update() to my pre middlware in order to use it in my log file but don't know how to do that.

user3711521
  • 285
  • 5
  • 14
  • Use `this._id`. `this` pointed to currently saved object. – alexmac Sep 22 '17 at 08:53
  • thank you, but if I want to use the req.user.id with another collection like Organization, problem is that Organization doesn't have the user id, so I really have to pass the req.user.id parameter – user3711521 Sep 22 '17 at 09:03

0 Answers0