Skip to content

Commit cab33cf

Browse files
committed
Use MongoDB connection string in DATABASES["HOST"]
1 parent 3b2ca28 commit cab33cf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

.github/workflows/mongodb_settings.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import os
22

3-
from django_mongodb_backend import parse_uri
3+
from pymongo.uri_parser import parse_uri
44

55
if mongodb_uri := os.getenv("MONGODB_URI"):
6-
db_settings = parse_uri(mongodb_uri, db_name="dummy")
7-
6+
db_settings = {
7+
"ENGINE": "django_mongodb_backend",
8+
"HOST": mongodb_uri,
9+
}
810
# Workaround for https://github.com/mongodb-labs/mongo-orchestration/issues/268
9-
if db_settings["USER"] and db_settings["PASSWORD"]:
10-
db_settings["OPTIONS"].update({"tls": True, "tlsAllowInvalidCertificates": True})
11+
uri = parse_uri(mongodb_uri)
12+
if uri.get("username") and uri.get("password"):
13+
db_settings["OPTIONS"] = {"tls": True, "tlsAllowInvalidCertificates": True}
1114
DATABASES = {
1215
"default": {**db_settings, "NAME": "djangotests"},
1316
"other": {**db_settings, "NAME": "djangotests-other"},

0 commit comments

Comments
 (0)