$push to an array in MongoDB with mongoose doesn't work -
errmsg: 'the field \'weight\' must array of type int in document
my schema:
weight: [{ type: number }] and 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'); } }) });
if there multiple documents in collection match conditions, can update suitable 1 adding { weight: { $type: 4 } } conditions.
otherwise application's schema doesn't match data in database.
Comments
Post a Comment