mongodb 已删除的文档保留在引用它们的另一个集合中
mongodb deleted documents remain in another collection that referenced them
我有以下例子:
const exampleSchema = new mongoose.Schema({
test: [{ type: mongoose.Schema.Types.ObjectId, ref: "Test" }],
});
const testSchema = new mongoose.Schema({
date: {
type: Date,
required: true,
},
});
TestSchema.index({ date: 1 }, { expireAfterSeconds: 0 });
当文档从 Test
集合中自动删除时,它们仍保留在 Example
集合中的引用。我可以修改什么以便它也从 Example
集合字段中删除?
在mongodb中,必须分两步删除Test,从Example中删除,然后自己删除。
MongoDB 不是关系数据库。
如果不同集合中的文档之间存在关系,则由应用程序创建、删除和维护关系。
我有以下例子:
const exampleSchema = new mongoose.Schema({
test: [{ type: mongoose.Schema.Types.ObjectId, ref: "Test" }],
});
const testSchema = new mongoose.Schema({
date: {
type: Date,
required: true,
},
});
TestSchema.index({ date: 1 }, { expireAfterSeconds: 0 });
当文档从 Test
集合中自动删除时,它们仍保留在 Example
集合中的引用。我可以修改什么以便它也从 Example
集合字段中删除?
在mongodb中,必须分两步删除Test,从Example中删除,然后自己删除。
MongoDB 不是关系数据库。
如果不同集合中的文档之间存在关系,则由应用程序创建、删除和维护关系。