Connecting to a MongoDB cluster (protocol mongodb+srv)

When using a MongoDB cluster, the mongo connection string has a protocol or scheme of mongodb+srv, for example:

mongodb+srv://openedx:password@dev.cluster1.mongodb.net:27017/openedx

This is the case, for example, when using Mongo Atlas to host MongoDB.

Has anyone managed to use Mongo Atlas clusters with Tutor?

When running forums, the constructed URL in tutor/templates/build/forum/bin/docker-entrypoint.sh would need to change from mongodb (hardcoded) to an environment variable that could be set to mongodb+srv?

For the LMS and CMS, it is less clear to me how to configure the mongo connection and I can’t find any mention of doing this in native OpenEdx documentation / forums.

Has anyone managed to use Mongo Atlas clusters with Tutor?

Hi @james_imsimbi! Tutor users must be able to connect to Atlas clusters, and the fact that the “mongodb+srv” connection string is not supported is considered as a bug – either in Tutor, Open edX or both.

I was not aware of this syntax, which is documented here: https://developer.mongodb.com/article/srv-connection-strings If I understand correctly, with “mongodb+srv” the server addresses are seeded from SRV DNS records.

We could easily modify the mongodb connection strings for the forums, but this change would not affect the connection string used in the LMS and CMS (in edx-platform). These apps use the pymongo library, for which the “mongodb+srv” syntax is supported: mongo_client – Tools for connecting to MongoDB — PyMongo 3.11.2 documentation

However, this new syntax requires that the MongoClient is instantiated by a single URI string. This is not the case in edx-platform: edx-platform/mongo_utils.py at 3c3e35e0f8f6e2d4093bd0175b318c296980a967 · edx/edx-platform · GitHub

It might be possible to redefine the “host” constructor argument in Tutor: tutor/common_all.py at 0f1dbf0ba59e6cd3d77cfb0ba86db6866bf2624e · overhangio/tutor · GitHub
If this does not work, we would have to make a change upstream, in edx-platform.

Unfortunately I do not have access to an Atlas cluster and I do not have the time to implement this change myself. Would you like to attempt making the change yourself? If not, this is typically the kind of change that would be the subject of a consulting contract (for which I would be available).

Hi @regis, thank you so much for your detailed response! I am happy to attempt the change and will respond here and make a PR with the results.