Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
How to merge the product.id with the req.body.categories into an array of string
const productSchema = mongoose.Schema({
 categories:  [{
   type: mongoose.Schema.ObjectId,
   ref: 'Category'
  }]
});

How do I generate an array like the following?

{
"categories":["5cd295fbc53f626fd9d70894","5cb0624945111f1c5fdf2527","5cc290f5b90fc527c1e46efd"]
}

When i use postman input using raw.json it can successfully push in but if i use urlencoded form input

categories:5cd295fbc53f626fd9d70894
categories:5cb0624945111f1c5fdf2527
categories:5cc290f5b90fc527c1e46efd

it only push the last id to the array

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The express.urlencoded middelware handles repeated arguments:

app.use(express.urlencoded({extended: false}), function(req, res) {
  res.end(req.body);
});

With this, the request

POST /server/path
Content-Type:application/x-www-form-urlencoded

categories=A&categories=B

returns

{"categories":["A","B"]}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda