Last active
April 10, 2018 18:13
-
-
Save rhanka/5842b18cfff070071149d8baadb9f915 to your computer and use it in GitHub Desktop.
Udata js domain migration for file resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* resource.filetype: migrate OLD_DOMAINS to NEW_DOMAIN | |
* WARNING : it uses a basic 'replace' without a strict regex, be careful about the OLD_DOMAINS | |
*/ | |
var count = 0; | |
var urlRegex = /^https?\:\/\/alpha.datalab.mi.*$/i; | |
db.dataset.find({'resources.filetype': 'file'}).forEach(function(dataset) { | |
if (dataset.resources) { | |
dataset.resources.forEach(function(resource) { | |
if (resource.filetype && resource.filetype == 'file') { | |
if (resource.url.match(urlRegex)) { | |
old_url = resource.url | |
resource.url = resource.url.replace('alpha.datalab.mi', 'catalog.datalab.mi') | |
print(`${old_url} => ${resource.url}`); | |
count++; | |
} | |
} | |
}); | |
db.dataset.save(dataset); | |
} | |
}); | |
print(`${count} resources updated.`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment