errmsg: 'The field \'weight\' must be an array but is of type int in document
My Schema:
weight: [{
type: Number
}]
and my post request:
app.post('/edit', function(req, res){
var update = { $push: {"weight": req.body.weight}};
User.findOneAndUpdate(conditions, update, options, function (err)
{
if (err)
{
console.log(err);
}
else
{
console.log('yep');
}
})
});
{"weight": 3}in db and you're using$pushto push array value intointtype field.weightfield first. It should look like{"weight": [3]}in db and you can use the update with$pushto add more values into array. So you possibly need like a update script to change the data first. See if this answer help. stackoverflow.com/questions/7401394/…