mongodb - 您可以创建一个虚拟而不是在模型(猫鼬)中添加直接引用吗?
问题描述
如果我有 Board 模型和 List 模型,并且想在获取列表时访问 boardId,我可以这样做:
const BoardSchema = new Schema(
{
title: {
type: String,
trim: true,
required: [true, "The Board title is required"],
},
},
{ timestamps: true }
);
const ListSchema = new Schema(
{
title: {
type: String,
trim: true,
required: [true, "The List title is required"],
},
boardId: {
type: ObjectId,
ref: "Board",
},
},
{ timestamps: true }
);
我可以通过使用虚拟属性而不boardId
直接添加到架构来做同样的事情吗?
解决方案
推荐阅读
- android - 我在带有卡片视图的类别区域网格视图中使用标志,我无法单击单击第二个图块我需要第二次按下它然后它选择
- php - 如何在购物车中添加两个产品 onlclick 添加到购物车按钮?
- python - 来自另一个模块的 Python 登录方法
- ios - 使用 Apple 登录:验证我的域无法正常工作
- javascript - sails.js 如何使用 restler 从脚本调用 REST API?
- windows-installer - 创建 Windows Installer MSI 以添加用于 Power Point 的插件
- xml - 使用 XSLT 将 CSV 文件转换为 XML
- google-cloud-platform - Google Cloud - 保险柜存储、用户名和密码
- python - 如何使用python生成显示百分比而不是出现次数的图表?
- flutter - Flutter Firestore 使用异步检索所有文档内容