MongoDB result backend does not work with mongodb+srv:// URL
Author: DlubakCreated May 6, 2022Updated Sep 12, 2026
LabelsIssue Type: Bug ReportComponent: MongoDB Results Backend
Checklist https://github.com/celery/celery/blob/master/celery/backends/mongodb.py#L136-L163
Steps to reproduce Set the MongoDB URL to one like:
celery_config.py
class CeleryConfig:
broker_url = broker_url
result_backend = "mongodb+srv://admin:[email protected]/"
accept_content = ["json"]
result_serializer = "json"
task_serializer = "json"
mongodb_backend_settings = {
"database": "steps",
"taskmeta_collection": "step",
}pyproject.toml
[tool.poetry.dependencies]
python = "^3.9"
boto3 = "^1.21.17"
celery = "^5.2.3"
mongoengine = "^0.24.1"celery_worker.py
# Initialization of Celery APP
app = Celery(backend=CELERY_BACKEND_URL)
app.config_from_object(CeleryConfig)Expected behavior This works.
Actual behavior:
celery worker log also states that url is changed from -> "mongodb+srv://admin:[email protected]/" to this -> mongodb://admin:[email protected]/ and it also adds default port to url and srv version of mongo cannot have port number in it.
-> which causes this exception to raise
ServerDescription ('testing.company.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('testing.company.mongodb.net:27017: [Errno -2] Name or service not known')>]>```Source: celery/celery