schema.pre('validate'), override `this`

49 views
Skip to first unread message

Vadorequest Mini Vado

unread,
Feb 14, 2014, 11:51:25 AM2/14/14
to mongoo...@googlegroups.com
Hi. I'm trying to use the middleware to add a default value, based on another document, in the pre validate event (not pre save because without this element the validation will fail).

I tried to do so, following the official mongoose documentation, but so far I failed.

I created a stackoverflow question about it but nothing useful yet so I'm asking here, hoping to be pointed out on the good direction.


Thanks.

Joe Wagner

unread,
Feb 14, 2014, 12:37:48 PM2/14/14
to mongoo...@googlegroups.com
It looks like you are not quite using parallel middleware correctly as well as not keeping a reference to the correct `this` in the outer scope of your query callback.

Joe Wagner

unread,
Feb 14, 2014, 12:38:35 PM2/14/14
to mongoo...@googlegroups.com
I put an answer on SO with more detail
Reply all
Reply to author
Forward
0 new messages