Skip to content

Instantly share code, notes, and snippets.

@reidransom
Last active November 23, 2015 16:30
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 reidransom/f4b72503e714e4db00a0 to your computer and use it in GitHub Desktop.
Save reidransom/f4b72503e714e4db00a0 to your computer and use it in GitHub Desktop.
Replace-All for edX Courses
$ mongo
> show dbs #optional
> use edxapp
> show collections #optional
> db.modulestore.find({'_id.category':'html'}).snapshot().forEach( function (e) {
e.definition.data.data = e.definition.data.data.replace(/http\:\/\/docs\.google\.com/g, '//docs.google.com');
db.modulestore.save(e);
})
# A more complex replace
> db.modulestore
.find({
'_id.category':'problem',
'metadata.display_name':'Text Input'
})
.snapshot()
.forEach(function (e) {
if (e.definition.data.data) {
e.definition.data.data = e.definition.data.data.replace(/stringresponse answer="\."/g, 'stringresponse answer=".+"');
}
if (e.metadata.markdown) {
e.metadata.markdown = e.metadata.markdown.replace(/stringresponse answer="\."/g, 'stringresponse answer=".+"');
}
db.modulestore.save(e);
})
# also see [regex matching](http://stackoverflow.com/questions/10610131/checking-if-a-field-contains-a-string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment