Consider this data
{
"_id" : ...,
"array" : [
{ "name" : "value1","flag" : true } ,
{ "name" : "value2","flag" : false }
]
}
I would like to toggle the 2nd array element (from false to true)
I know I can update a specific element using the very useful $ positional operator like this:
db.myCollection.update(
{'array.name':'value2'},
{
$set: {
'array.$.flag':true
}
},false,true);
But is there a way to use the $ positional operator also for the value setting?
e.g. like this?
db.myCollection.update(
{'array.name':'value2'},
{
$set: {
'array.$.flag':'!array.$.flag' //<--
}
},false,true);