Skip to content

Commit 2bdd259

Browse files
committed
Get the host and name
1 parent f1e1d44 commit 2bdd259

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

django_mongodb/utils.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,29 @@ def check_django_compatability():
2828

2929
def parse(uri):
3030
uri = parse_uri(uri)
31-
32-
# If fqdn is None then this is not a SRV URI, so we need to extract the port
33-
# from the first node in the nodelist.
31+
name = None
3432
port = None
33+
3534
if uri["fqdn"] is None:
35+
# If fqdn is None then this is not a SRV URI, so we need to extract the
36+
# port from the first node in the nodelist.
3637
if "nodelist" in uri and isinstance(uri["nodelist"], list) and len(uri["nodelist"]) > 0:
3738
first_node = uri["nodelist"][0]
3839
if isinstance(first_node, tuple) and len(first_node) > 1 and isinstance(first_node[1], int):
3940
port = first_node[1]
41+
else:
42+
# The fqdn is not none so we need to add the mongodb+srv:// prefix to the host.
43+
host = f"mongodb+srv://{uri['fqdn']}"
4044

41-
return {
45+
url = {
4246
"ENGINE": "django_mongodb",
43-
"HOST": uri["fqdn"] or None,
47+
"NAME": uri["database"],
48+
"HOST": host,
4449
"PORT": port,
4550
"USERNAME": uri.get("username"),
4651
"PASSWORD": uri.get("password"),
4752
}
53+
return(url)
4854

4955

5056
def set_wrapped_methods(cls):

0 commit comments

Comments
 (0)