[英]How to add an array of objects in Mongoose Schema
can someone help me? 有人能帮我吗?
I'm trying to update my Mongoose Schema and add to it an Array like this : I want to add to my ProductSchema the "attribute" ( I don't know how we call this, sorry ^^') description and in this description, you have multiple attributes lile brand, model, size, color, ... 我正在尝试更新我的Mongoose模式,并向其中添加一个数组,如下所示:我想向我的ProductSchema中添加“属性”(我不知道我们怎么称呼它,对不起^^')描述和此描述,您有多个属性lile品牌,型号,尺寸,颜色,...
I did something like this but (I don't think it worked) : 我做了这样的事情,但是(我认为这没有用):
...
description: [
{ brand: String },
{ model: String },
{ size: String },
{ color: String },
{ year: Number },
{ State: String }
]
...
Thank's for your time ! 谢谢你的时间 !
UPDATE: 更新:
In fact, I don't need an array for the description, that was a stupid question ^^' 实际上,我不需要描述数组,那是一个愚蠢的问题^^'
I can do something like this : 我可以做这样的事情:
...
description: {
brand: String,
model: String,
size: String,
color: String,
year: Number,
State: String
}
...
Sure, you don't need an array if there is only one "decription" in your document schema. 当然,如果文档架构中只有一个“描述”,则不需要数组 。
However, if you need to store multiple descriptions, you can use : 但是,如果您需要存储多个描述,则可以使用:
...
description: [{
brand: String,
model: String,
size: String,
color: String,
year: Number,
State: String
}]
In your first attempt, you've made each property of your object an object itself. 在第一次尝试中,您已经将对象的每个属性变成了对象本身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.