Friday 19 May 2017

How to set "updatedBy" automatically in Mongoose model hooks

Say we have a Mongoose schema hook like so:

someSchema.pre('save', function(next){
  this.updatedBy = // assign to the logged in user  <<<<
  this.updatedAt(new Date());
  next();
});

how can I pass the logged-in user information to this hook?

Seems very difficult to do, the way it is by default.



via Alexander Mills

No comments:

Post a Comment