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
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"]}