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

119
Views
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 answers
Answer question

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 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!