Chr*_* K. 1 javascript mongoose mongodb node.js
我有这个代码:
postSchema.pre('deleteMany', async function (next: NextFunction) {
try {
console.log(this);
return next(); // normal save
} catch (error) {
return next(error);
}
});
Run Code Online (Sandbox Code Playgroud)
console.log正在给予query object. 文档可以在 中的某个地方找到吗query?
查询deletemany位于 的_conditions键this,因此您可以在帖子模型中执行以下操作,例如:
postSchema.pre('deleteMany', async function (next: NextFunction) {
try {
let deletedData =await Post.find(this._conditions).lean()
console.log(deletedData );
return next(); // normal save
} catch (error) {
return next(error);
}
});
let Post= mongoose.model("Post", userSchema);
module.exports = Post
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2254 次 |
| 最近记录: |