Skip to content

Instantly share code, notes, and snippets.

View vonox7's full-sized avatar

Valentin Slawicek vonox7

View GitHub Profile
@vonox7
vonox7 / migrateStrings.js
Last active December 21, 2020 20:43 — forked from rajiteh/mongo_search_and_replace.js
Recursive MongoDB fulltext deep string replacement migration
/*
Recursively traverses all collections and objects/arrays contained within documents replacing every
instance of 'find' with 'replace'.
mongo <db_name> mongo_search_and_replace.js
*/
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}