我想在 findOneAndRemove
预挂钩期间获取已删除的文档数据以进行一些操作,但我无法从 "this"
实例中找到文档数据(通过记录 "this"
)。
我怎样才能删除文档数据?
album_schema.pre('findOneAndRemove', async function (next) {
let self = this;
// self.title is undefined , naturally self.artists is also undefined
if (self.artists && self.artists.length) {
for (let artist_id of self.artists) {
await User.findByIdAndUpdate(artist_id, { $pull: { albums: self._id } })
}
}
next()
})