Here's one way that might work by deconstructing the current "slug" into "allowable" characters and then "$concat" the chars back into a single string. I have little regex-foo so I'm not sure this is the best "regex", but it may be sufficient. If your data is important, you should probably test this on some toy data first.
db.collection.update({},
[
{
"$set": {
"slug": {
"$rtrim": {
"chars": "-",
"input": {
"$reduce": {
"input": {
"$regexFindAll": {
"input": "$slug",
"regex": "[\\p{Xan}-]+"
}
},
"initialValue": "",
"in": {"$concat": ["$$value", "$$this.match"]}
}
}
}
}
}
}
],
{"multi": true}
)
Try it on mongoplayground.net.
UPDATE
This is a bit ugly, and demonstrates my lack of regex-foo, but by adding another stage to execute a javascript "$function", multiple - can be collapsed to just one. Hopefully a regex master will see this and simplify the whole thing.
db.collection.update({},
[
{
"$set": {
"slug": {
"$rtrim": {
"chars": "-",
"input": {
"$reduce": {
"input": {
"$regexFindAll": {
"input": "$slug",
"regex": "[\\p{Xan}-]+"
}
},
"initialValue": "",
"in": {"$concat": ["$$value", "$$this.match"]}
}
}
}
}
}
},
{
"$set": {
"slug": {
"$function": {
"lang": "js",
"args": ["$slug"],
"body": "function(str) {return str.replace(RegExp('-+', 'g'), '-')}"
}
}
}
}
],
{
"multi": true
})
Try it on mongoplayground.net.