Mongodb ServerSelectionTimeoutError

I am trying to connect to MongoDB on mongodb atlas. The tutor application is running on an ec2 instance. In the mongodb atlas metrics, I can see the connections being made, but still leading to this error.
Im using tutor version 13.1.0.
Have configured mongodb with below configs:

tutor config save --set RUN_MONGODB=false \
                            --set MONGODB_HOST="mongodb://<username>:<password>,,"  \
                            --set MONGODB_PORT=27017 \
                            --set MONGODB_DATABASE="edxapp"

While importing the democourse(tutor local importdemocourse), Iā€™m getting the following error:

2022-05-07 06:13:34,739 WARNING 15 [root] [user None] [ip None] - XBlock <class 'xblock.internal.DiscussionXBlockWithMixins'> does not contain field url_name
2022-05-07 06:13:34,755 WARNING 15 [root] [user None] [ip None] - XBlock <class 'xblock.internal.DiscussionXBlockWithMixins'> does not contain field url_name
2022-05-07 06:13:34,770 WARNING 15 [root] [user None] [ip None] - XBlock <class 'xblock.internal.DiscussionXBlockWithMixins'> does not contain field url_name
2022-05-07 06:13:34,920 INFO 15 [xmodule.modulestore.xml] [user None] [ip None] - Course import None: Done with courselike import from ../edx-demo-course
Traceback (most recent call last):
  File "/openedx/venv/lib/python3.8/site-packages/", line 55, in wrapper
    return func(*args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/", line 1273, in find_one
    for result in cursor.limit(-1):
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/", line 1156, in next
    if len(self.__data) or self._refresh():
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/", line 1050, in _refresh
    self.__session = self.__collection.database.client._ensure_session()
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/", line 1810, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/", line 1763, in __start_session
    server_session = self._get_server_session()
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/", line 1796, in _get_server_session
    return self._topology.get_server_session()
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/", line 482, in get_server_session
  File "/openedx/venv/lib/python3.8/site-packages/pymongo/", line 208, in _select_servers_loop
    raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: connection closed

I manually added the following configs in ~/.local/share/tutor/env/apps/openedx/settings/cms/ and restarted (tutor local restart), issues seemed to be fixed.

mongodb_parameters['replicaSet'] = 'atlas-vpw4f2-shard-0'
mongodb_parameters['authsource'] = 'admin'

The MongoDB parameters generated were:

mongodb_parameters = {
    "host": "mongodb://<username>:<password>,,>
    "port": 27017,
    "db": "openedx",
    "ssl": True,
    "user": None,
    "password": None,

@regis Is it possible to set these parameters using tutor config .. --set ..? Those parameters can be optional I guess.
I would be happy to open a PR for this if there are no other things might me messed because of these changes.

You can do it using a plugin, take a look here: plugin-development-tutorial.

1 Like

Got it. Thanks @erickhgm .

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.