javascript - 如何在模式中创建嵌套字段?
问题描述
假设我有这个用户模式,它有一个带有多个插槽的库存。我如何将这些 slotsimg 和 slottext 字段嵌套在库存字段中?
例如像这样:
const UserSchema = new mongoose.Schema({
Inventory: {
slot1img: {
type: String,
},
slot1text: {
type: String,
},
slot2img: {
type: String,
},
slot2text: {
type: String,
},
slot3img: {
type: String,
},
},
});
但是,如果我这样尝试,它根本不会出现在数据库中,那么我该怎么做呢?
解决方案
我找到了一个解决方案:https ://docs.mongodb.com/manual/tutorial/model-embedded-one-to-many-relationships-between-documents/#embedded-document-pattern 。如果其他人遇到此问题,请使用链接:)
推荐阅读
- django - 如何在 django 中编辑模板时显示选中的项目和上传的图像值
- javafx - 如何在 javafx 中打开带有标签、文本字段等的新窗口?
- wordpress - 如何将占位符图标放入联系表格 7?
- html - HTML 输入模式属性
- node.js - 由于安装位置已被删除,无法全局卸载此 node.js 包
- c# - 在列表框中选择项目时尝试显示数据集中行的所有值
- python - 如何强制 Python (EMCEE) 在先前定义的范围之间精确移动
- laravel - 如何在不同的 Laravel 控制器中重用自定义函数?
- spring-mvc - java.lang.IllegalStateException:没有为 servlet 请求找到匹配的处理程序方法
- php - Codeigniter - 使用 MySql 从具有多个重复 MaxDate/time 的元表中获取数据