我在猫鼬中有这个模式,当我使用带有更新的 pre 时,我得到了这个错误。
JobSchema.pre('update', function(n){n()})
完全错误
C:\web\production01_server\node_modules\production\node_modules\mongoose\lib\utils.js:413
throw err;
^
TypeError: Cannot read property 'numAsyncPres' of undefined
at Model._lazySetupHooks (C:\web\production01_server\node_modules\production\node_modules\mongoose\node_modules\hooks\hooks.js:149:49)
at Model.pre (C:\web\production01_server\node_modules\production\node_modules\mongoose\node_modules\hooks\hooks.js:113:10)
at Model.doQueue (C:\web\production01_server\node_modules\production\node_modules\mongoose\lib\document.js:1116:41)
at Model.Document (C:\web\production01_server\node_modules\production\node_modules\mongoose\lib\document.js:55:8)
at Model.Model (C:\web\production01_server\node_modules\production\node_modules\mongoose\lib\model.js:26:12)
at Model.model (C:\web\production01_server\node_modules\production\node_modules\mongoose\lib\model.js:910:11)
at new Model (C:\web\production01_server\node_modules\production\node_modules\mongoose\lib\connection.js:418:15)
at cb (C:\web\production01_server\node_modules\production\node_modules\mongoose\lib\query.js:804:16)
at C:\web\production01_server\node_modules\production\node_modules\mongoose\lib\utils.js:408:16
at C:\web\production01_server\node_modules\production\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cursor.js:133:9
笔记:
- pre('保存' WORKS
- post('update' 不会抛出错误并且不起作用