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

458
Visualizações
Pushing Array of object from react to mongodb+express server issue

I'm store array of object but it is giving mer following error.

(node:87929) UnhandledPromiseRejectionWarning: ValidationError: Place validation failed: placesToVisit: Cast to embedded failed for value "[{"name":"xczc","location":"zczxc","description":"czxczx"}]" (type string) at path "placesToVisit" because of "ObjectParameterError"

here is my schema:

placesToVisit: [
    {
      name: {
        type: String,
        required: [true, "Please enter the place's name"],
      },
      description:{
        type: String,
        required: [true, "Please enter the place's description"],
      },
      location:{
        type: String,
        required: [true, "Please enter the place's location"],
      }
    },
  ],

here is my contoller:

exports.createPlace = async (req, res) => {
  
  try {
    const newPlace = await new Place({
    
     placesToVisit:req.body.placesToVisit,
    
    });
    newPlace.save()
    debugger
    res.status(201).json({
        success:true,
        message:"Place Created Successfully",
        newPlace
    })
  } catch (error) {
     return res.status(500).json({
          success:false,
          error:error.message
      })
  }
};

here is my formdata structure:

data.append("placesToVisit",JSON.stringify(values.placesToVisit))

here is ss of yaload enter image description here

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You must convert the string to an array:

placesToVisit: JSON.parse(req.body.placesToVisit),
over 4 years ago · Santiago Trujillo 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