I am trying to increment a value of an element here's my array object
"options": [
{
"key": "banana",
"votes": 0
},
{
"key": "apple",
"votes": 0
},
{
"key": "mango",
"votes": 0
},
{
"key": "grapes",
"votes": 0
}
]
im trying to increment the votes value of the selected
item while also matching the id of that data
db().collection('polls').update(
{ _id: id, "options.key": item },
{$set: { $inc: { "options.$.votes" : 1 } }})
But it didn't work... the db() here is a function that returns the db.. im not getting any errors.
here is the full data
{
"_id": {
"$oid": "5aae26203ab1cc0f15e43dc6"
},
"author": "me",
"title": "fruits you love the most",
"options": [
{
"key": "banana",
"votes": 0
},
{
"key": "apple",
"votes": 0
},
{
"key": "mango",
"votes": 0
},
{
"key": "grapes",
"votes": 0
}
]
}