I am using mongoose (on node) and I am trying to add some extra fields to the model for saving using Mongoose middleware.
I take a commonly used case to add a lastmodifiedsince date. However, I also want to automatically add the name / profile for the user who performed the save.
schema.pre('save', function (next) {
this.lasteditby=req.user.name;
this.lasteditdate = new Date();
next()
})
I use a passport - http://passportjs.org/ - as a result, req.user is present req, of course, which is an http request.
thank
EDIT
pre , save . , ( arg ), , .