$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

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -