【发布时间】:2021-12-28 01:08:38
【问题描述】:
我正在尝试应用主题中使用的方法来根据所选标准管理同一商品的不同价格: MongoDB Schema for ecommerce products that have variations with different SKUs, prices and stock
但是关于这个方案:
dimensions: {
color: {
title: { type: String },
red: {
title: { type: String },
images: [{ type: String }],
},
},
size: {
title: { type: String },
s05: {
title: { type: String },
images: [{ type: String }],
},
},
variations: [
{
dimensions: {
color: { type: String },
size: { type: String },
fireretardant: { type: String },
},
SKU: { type: String },
price: { type: Number },
},
],
},
当我尝试创建一个对象时,我得到了这个错误:
file:///C:/Users/ReactProject/shop-v2/backend/data.js:68 尺寸:{颜色:红色,尺寸:s1,阻燃:无}, ReferenceError:红色未定义
如何让 Mongoose 考虑定义的红色和大小?
dimensions: {
color: {
title: "Color",
red: {
title: "Red",
images: [
"http://myserver.com/images/product_12345_3",
"http://myserver.com/images/product_12345_4",
],
},
},
size: {
title: "Size",
s05: {
title: "0.5 m",
images: [],
},
},
variations: [
{
dimensions: { color: red, size: s1 },
SKU: "98765",
price: 10,
},
],
},
【问题讨论】:
标签: javascript reactjs mongoose variations