Database

[{"_id":{"$oid":"630f3c32c1a580642a9ff4a0"},"title":"This is a title [Hello#$There1234] !!5678 @","slug":"this-is-a-title-[hello#$there1234]-!!5678-@","Post":"this is a post"},{"_id":{"$oid":"630f3c32c1a580642a9ff4a1"},"title":"Tohle je můj oblíbený titul [Hello#$There1234] !!5678 @/","slug":"Tento-je-můj-oblíbený-titul-[hello#$there1234]-!!5678-@/","Post":"this is a post"},{"_id":{"$oid":"630f3c32c1a580642a9ff4a2"},"title":"这是我最喜欢的标题 [Hello#$There1234] !!5678 @","slug":"这是我最喜欢的标题-[hello#$there1234]-!!5678-@%","Post":"this is a post"},{"_id":{"$oid":"630f3c32c1a580642a9ff4a3"},"title":"這是我最喜歡的標題 [Hello#$There1234] !!5678 @","slug":"這是我最喜歡的標題-[hello#$there1234]-!!5678-@-^","Post":"this is a post"},{"_id":{"$oid":"630f3c32c1a580642a9ff4a4"},"title":"यह-मेरा-पसंदीदा-शीर्षक है [Hello#$There1234] !!5678 @","slug":"यह-मेरा-पसंदीदा-शीर्षक है-[hello#$there1234]-&*()_+=?-,.<->!-!5678-@","Post":"this is a post"}]

Query

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})

Result