diff --git a/common/lib/xmodule/xmodule/contentstore/mongo.py b/common/lib/xmodule/xmodule/contentstore/mongo.py index b5235e6745..9a99006e61 100644 --- a/common/lib/xmodule/xmodule/contentstore/mongo.py +++ b/common/lib/xmodule/xmodule/contentstore/mongo.py @@ -14,9 +14,13 @@ from xmodule.exceptions import NotFoundError class MongoContentStore(ContentStore): - def __init__(self, host, db, port=27017): + def __init__(self, host, db, port=27017, user=None, password=None, **kwargs): logging.debug( 'Using MongoDB for static content serving at host={0} db={1}'.format(host,db)) - _db = Connection(host=host, port=port)[db] + _db = Connection(host=host, port=port, **kwargs)[db] + + if self.user is not None and self.password is not None: + _db.authenticate(user, password) + self.fs = gridfs.GridFS(_db) self.fs_files = _db["fs.files"] # the underlying collection GridFS uses diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index 30ae5c7539..164bfd3590 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -97,15 +97,21 @@ class MongoModuleStore(ModuleStoreBase): # TODO (cpennington): Enable non-filesystem filestores def __init__(self, host, db, collection, fs_root, render_template, port=27017, default_class=None, - error_tracker=null_error_tracker): + error_tracker=null_error_tracker, + user=None, password=None, **kwargs): ModuleStoreBase.__init__(self) self.collection = pymongo.connection.Connection( host=host, - port=port + port=port, + **kwargs )[db][collection] + if user is not None and password is not None: + self.collection.database.authenticate(user, password) + + # Force mongo to report errors, at the expense of performance self.collection.safe = True