$push to an array in MongoDB with mongoose doesn't work $push to an array in MongoDB with mongoose doesn't work mongoose mongoose

$push to an array in MongoDB with mongoose doesn't work


If there are multiple documents in the collection that match your conditions, you can update only suitable one by adding { weight: { $type: 4 } } to your conditions.

Otherwise your application's schema doesn't match data in the database.


This might work.

//Schema

weight: [Number]

http://mongoosejs.com/docs/schematypes.html

//Or this way too if pushing objects into array

//Schema

weight: [{  weight: {    type: Number  }}]

//Then in API

var update = {  $push: {"weight": { "weight": req.body.weight }}};