I am trying to apply the method used in topic to manage different prices of a same item based on its selected criteria : MongoDB Schema for ecommerce products that have variations with different SKUs, prices and stock
But regarding this scheme :
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 },
},
],
},
When I try to create an object, I get this error :
file:///C:/Users/ReactProject/shop-v2/backend/data.js:68 dimensions: { color: red, size: s1, fireretardant: no }, ReferenceError: red is not defined
How to get Mongoose to consider red & size as defined ?
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,
},
],
},
The issue is coming from this line
dimensions: { color: red, size: s1 }
The color and size are set to variables. Did you mean to enter them as strings? If so, try:
dimensions: { color: "red", size: "s1" }
If they are meant to be variables, then check that these variables have been defined, and that they are available in the scope of the given function call.
The error means that it is looking for the variable named red, but it did not find it.