繁体   English   中英

我可以使用mongodb ref引用同一模型中的模型吗

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM