You can use an [update with aggregation pipeline], something like this,
Considering you are searching for the tag name “red”, we have assigned a tagName variable. we will use that variable in the query.
You need to wrap the update part in an array bracket because we are using an update with an aggregation pipeline.
$cond to check if tagName exists in tags array or not.
If exists then, do $map, iterate tags array, and check if tagName matches then update the count from tagCount variable otherwise return the current object.
Otherwise, add the new tag by $concatArrays operator.