Skip to content

Instantly share code, notes, and snippets.

@joadr
Created September 1, 2016 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joadr/ec1e4ba731988e9dc7a3d47b91789f87 to your computer and use it in GitHub Desktop.
Save joadr/ec1e4ba731988e9dc7a3d47b91789f87 to your computer and use it in GitHub Desktop.
Mongo gridfs meteor url changer
// When meteor starts
Meteor.startup(function () {
// Recursive function to replace urls
function fixUrl (object) {
_.map(object, function (value, key) {
if (_.isArray(value)) {
_.map(value, function (value2, key2) {
value2 = fixUrl(value2)
})
} else if (_.isObject(value)) {
if (value.url) {
value.url = value.url.replace('http://localhost:3000/', 'http://raicap.com/') // change urls part you whant to change
} else {
value = fixUrl(value)
}
}
})
return object
}
var newDoc = fixUrl(orion.dictionary.findOne())
delete newDoc._id
orion.dictionary.update({}, {$set: newDoc })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment