[英]Can I use the mongodb ref to reference a model in that same model
假设我有一个名为Task
的模型,该模型具有一个称为dependencies
的字段,并且dependencies
字段的类型为mongodb ID,我希望它可以作为对Task
模型本身的引用。 我不知道mongodb和mongoose是否可行。
例如:
// Task model
const taskSchema = mongoose.Schema({
// other fields
// dependencies: [{
types: mongoose.Schema.Types.ObjectId,
ref: 'Task' // is this possible?at what cost?
}]
})
modules.export = mongoose.model('Task', taskSchema)
是的,在MongoDB和Mongoose中也可以嵌套。 尽量避免深度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.