我的架构如下:
const Author = new Schema({
name: String,posts: [{ type: mongoose.Schema.Types.ObjectId,ref: "Post" }]
});
const Post = new Schema({
text: String,author: { type: mongoose.Schema.Types.ObjectId,ref: "Author" }
});
如果我使用deleteMany()
删除一堆帖子,从作者对象中删除ObjectId条目的最佳方法是什么?
我尝试使用deleteMany
前置钩,但是它仅传递删除了多少文档,而不传递帖子的实际ObjectId。