My object looks like this:
Stats = {
name: 'filters'
variants: [
{
variant: 'A'
displayed: 123
actions: [
{
name: 'clicked'
triggered: 12
}
]
},
{
variant: 'B'
displayed: 123
actions: [
{
name: 'clicked'
triggered: 12
}
]
}
]
}
I have an array of variants and inside it array of actions. I would like to increment triggered field for selected variant and actions.name. I am using that in meteor.js.
My find query looks like below:
Stats.find({
name: 'filters',
variants: {
$elemMatch: {
variant: 'A',
'actions.name': 'clicked'
}}})
Now if object exists I would like to do something like below, but I know it doesn't work.
Stats.update({
name: 'filters',
variants: {
$elemMatch: {
variant: 'A',
'actions.name': 'clicked'
}}},
{
$inc: {
'variants.$.actions.$.triggered': 1
}})
I know that the positional $ operator acts as a placeholder for the first match of the update query selector. But maybe you have any other idea how to do it?