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.
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
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).
MONGODB_PROTOCOL can be set to mongodb+srv for a cluster MONGODB_PARAMS is optional for adding query parameters to the URI (it must start with ?)
This change is propsoed to env/build/forum/bin/docker-entrypoint.sh:
#!/bin/sh -e
if test "$MONGODB_PROTOCOL" = 'mongodb+srv'; then
export MONGOHQ_URL="$MONGODB_PROTOCOL://$MONGODB_AUTH$MONGODB_HOST/cs_comments_service$MONGODB_PARAMS"
export MONGO_WAIT=""
else
export MONGOHQ_URL="$MONGODB_PROTOCOL://$MONGODB_AUTH$MONGODB_HOST:$MONGODB_PORT/cs_comments_service$MONGODB_PARAMS"
export MONGO_WAIT="-wait tcp://$MONGODB_HOST:$MONGODB_PORT"
echo "Waiting for mongodb..."
fi
echo "Waiting for elasticsearch..."
dockerize $MONGO_WAIT -wait $SEARCH_SERVER -wait-retry-interval 5s -timeout 600s
exec "$@"
If the MONGODB_PROTOCOL is set to mongodb+srv then there are two key changes:
The port must not be included in the URL
The host cannot be used as a true server name for “waiting” because it is a DNS entry with only SRV records. I have elected not to wait at all for a cluster because it is unlikely that this cluster is starting up at the same time as the forum, because it is typically provisioned beforehand.
@regis , I attempted to commit a branch with a view to created a PR, but it seems there is no general access to do this. What is the process for creating a PR?
@regis sorry that I did not get this finished for the lilac release. Before submitting a new PR, I want to discuss some of what I have found:
While the URI works as the host parameter in pymongo (after adding the dnspython module) we still need to set parameters for ssl, replica_set and the auth_source database - I have not had time to investigate why this is - I am guessing it has to do with the version of pymongo, because, as mentioned previously, when I test the URI outside of edx it worked fine without these parameters
I have managed to get tutor 12.0 to work with a mongo atlas cluster (by adding the above parameters), largely the same as what I did before, except I have removed the MONGODB_PROTOCOL parameter.
I can spend a bit more time on it to find an elegant solution.