I'm inserting a data into an array but when I insert the data, it overwrites the whole array, here is my router for updating array
router.put('/editbloodbankarray', function(req, res) {
var editUser = req.body._id;
var newName = req.body.bloodbank_array;
User.findOne({ _id: editUser }, function(err, user) {
if (err) throw err;
user.bloodbank_array = newName;
// Save changes
user.save(function(err) {
if (err) {
res.json({ success: false, message: 'error' });
} else {
res.json({ success: true, message: 'Name has been updated!' });
}
});
});
});
sample document:
_id:5c8521c377df3158d0555db1,
bloodbank_array:
[
0:"1"
1:"2"
]
When I update/insert new item for example: 3..the array turns to:
_id:5c8521c377df3158d0555db1,
bloodbank_array:
[
0:"3"
]