Thanks, I already looked into it, but $addToSet alone would not remove the one I want to replace. And I can’t figure out how to do both at the same time.
MongoServerError: Updating the path 'flags' would create a conflict at 'flags'
Somewhere i read that this means I can’t modify the same field multiple times in one update query.
And I tried using an aggregation pipeline instead, but I don’t unterstand how to use $addToSet in there, because as described in the docs the only stages accepted are $addFields/$set $project/$unset $replaceRoot/$replaceWith.