Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
React Mongoose item price based on variations

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,
          },
        ],
      },
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!