我知道如何在 Mongoose 中引用文档,但有些事情我不清楚。
到目前为止我所知道的基本上是:
const Task = mongoose.model('task' , {
description : {
type : String ,
require : true ,
trim : true
} ,
completed : {
type : Boolean ,
default : false
} ,
owner : {
type : mongoose.Schema.Types.ObjectId ,
required : true ,
ref : 'User'
}
})
但我不明白的是猫鼬如何与 Users 模型的 _id 相关,为什么其他一些字段没有相同的类型。让我用更复杂的方式重新表述一下,如果我的 owner 类型设置为 String ,那么 String< 可以有 多个 字段/strong> 输入 Users 模型。那么我们如何引用它?