我有这个代码:
postSchema.pre('deleteMany', async function (next: NextFunction) {
try {
console.log(this);
return next(); // normal save
} catch (error) {
return next(error);
}
});
console.log
给出了query
object
。文档是否在query
中的某个位置可用?
我有这个代码:
postSchema.pre('deleteMany', async function (next: NextFunction) {
try {
console.log(this);
return next(); // normal save
} catch (error) {
return next(error);
}
});
console.log
给出了query
object
。文档是否在query
中的某个位置可用?
2条答案
按热度按时间zbwhf8kr1#
query in
deletemany
位于this
的_conditions
键处,因此您可以在Post Model中这样做,例如:ukxgm1gy2#
this.getFilter()
和this.getUpdate()
是访问中间件中参数的推荐方法链接到有关访问中间件的Mongoose文档