Last active
November 23, 2015 16:30
-
-
Save reidransom/f4b72503e714e4db00a0 to your computer and use it in GitHub Desktop.
Replace-All for edX Courses
This file contains hidden or 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
$ 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