I've got a problem updating an array element in MongoDB. This is the structure of a document:
{
"_id" : ObjectId("57e2645e11c979157400046e"),
"site" : "BLABLA",
"timestamp_hour" : 1473343200,
"values" : [
{
"1473343200" : 66
},
{
"1473344100" : 230
},
{
"1473345000" : 479
},
{
"1473345900" : 139
}
]
}
Now I want to update the element with key "1473345900". How can I do this? I've tried:
db.COLLECTIONNAME.update({"values.1473345900": {$exists:true}}, {$set: {"values.$": 0}})
But after that the document looks like:
{
"_id" : ObjectId("57e2645e11c979157400046e"),
"site" : "BLABLA",
"timestamp_hour" : 1473343200,
"values" : [
{
"1473343200" : 66
},
{
"1473344100" : 230
},
{
"1473345000" : 479
},
0
]
}
What I'm doing wrong? I only want to update the value of 1473345900 to any value... I don't want to update the complete element...
Thanks a lot!!!