天道酬勤,学无止境

mongoose-q

Mongoose post-remove 事件不会触发(Mongoose post-remove event doesn't fire)

问题 我的模型中有此代码: ContentSchema.post( 'remove', function( item ) { index.deleteObject( item._id ) }) 这是我的控制器中的内容: Content.find( { user: user, _id: contentId } ) .remove( function ( err, count ) { if ( err || count == 0 ) reject( new Error( "There was an error deleting that content from the stream." ) ) resolve( "Item removed from stream" ) }) 我期望当控制器中的函数运行时,模型中的函数应该发生。 我可以在调试器中看到它根本不触发。 我正在使用"mongoose": "3.8.23"和"mongoose": "3.8.23" "mongoose-q": "0.0.16" 。 回答1 remove事件(和其他中间件挂钩)不会在模型级方法上触发。 如果您使用实例方法,例如: Content.findOne({...}, function(err, content){ //... whatever you need to do prior to removal

2021-09-19 02:46:46    分类:技术分享    node.js   mongodb   mongoose   mongoose-q

Mongoose post-remove event doesn't fire

I have this code in my model: ContentSchema.post( 'remove', function( item ) { index.deleteObject( item._id ) }) Here's what's in my controller: Content.find( { user: user, _id: contentId } ) .remove( function ( err, count ) { if ( err || count == 0 ) reject( new Error( "There was an error deleting that content from the stream." ) ) resolve( "Item removed from stream" ) }) I expect that when the function in the controller runs, the function in the model should happen. I can see in the debugger it does not fire at all. I'm using "mongoose": "3.8.23" and "mongoose-q": "0.0.16".

2021-06-23 15:40:14    分类:问答    node.js   mongodb   mongoose   mongoose-q