所以基本上,我想在帖子挂钩上的name
之后对称为findOneAndUpdate
的字段进行分析。这是我在tourModel.js
中的代码:
tourSchema.post(/^findOneAnd/,async function() {
this.preslug = await this.findOne();
this.preslug.slug = slugify(this.preslug.name,{ lower: true });
this.findOneAndUpdate({ _id: this.preslug.id },{ slug: this.preslug.slug });
});
它确实可以在pre
钩子上工作,但是解析为name
的{{1}}是文档更新前的旧this.preslug.name
。有解决方案吗?