node.js - 如何在 Mongoose 中将一个模型引用到另一个模型?
问题描述
我知道如何在 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'
}
})
但我不明白的是,mongoose 与用户模型的_id有什么关系,为什么其他一些字段没有相同的类型。让我更复杂地改写一下,如果我的所有者类型设置为String ,用户模型中可以有多个String类型的字段。那么我们如何引用它呢?
解决方案
推荐阅读
- mysql - 在自动增量字段中加载超过 10000 个产品数据
- excel - 将 Excel 公式转换为 Power BI
- java - 数据处理平衡
- mysql - Mysql 正确比较日期
- powershell - 使用 powershell 上的 Skype 在线连接器获取用户的 Skype 状态
- django-rest-framework - 使用 Django Rest 在多级嵌套序列化程序中获取数据
- javascript - 我如何同时遍历三个 div 框
- java - 如何在运行时切换绑定(Camel Rest Dsl)
- jinja2 - Jinja2 只有小写的布尔值
- codeigniter - Codeigniter 中的重定向和 this 有什么区别?