currently I have a problem with updating existing JSON data using mongoose for nodejs. Here is my JSON data:
{
"_id" : ObjectId("59fb4d91fa90e127d41ed7f5"),
"heroes": [
{
"name": "antimage",
"id": 1,
"localized_name": "Anti-Mage",
"_id" : ObjectId("59fc7230728a3e28203151a0")
},
{
"name": "axe",
"id": 2,
"localized_name": "Axe",
"_id" : ObjectId("59fc7230728a3e28203111a4")
}
]
}
Here is my update request :
// update a hero in the db
router.put('/heroes/:id', function (req, res, next) {
//var id1 = req.params.id1;
//var id = req.params.id;
Hero.update({ _id: '59fb4d91fa90e127d41ed7f5', 'heroes._id': req.params.id },
{
$push: {
'heroes.$.name': req.body.name,
'heroes.$.id': req.body.id,
'heroes.$.localized_name': req.body.localized_name
}
}, { upsert: true }, function (err, docs) {
res.json(docs);
console.log(docs);
});
})
it giving me this in the console:
{
"ok": 0,
"n": 0,
"nModified": 0
}
It makes me can't sleep, Btw thanks for your help.