$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

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -