Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda