Skip to content

Commit 2ef9fe6

Browse files
committed
refactor
1 parent 65d2658 commit 2ef9fe6

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

django_mongodb/utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@ def parse(uri):
3131
host = None
3232
port = None
3333

34-
if uri["fqdn"] is None:
35-
# If fqdn is None this is not a SRV URI so extract host and port from
36-
# the first node in nodelist.
37-
host, port = [f"{node[0]}:{node[1]}" for node in uri["nodelist"]][0].split(":")
38-
else:
39-
# The fqdn is not none so we need to add the mongodb+srv:// prefix to
40-
# the host.
34+
if uri["fqdn"] is not None:
35+
# If the fqdn is present, this is a SRV URI and the host is the fqdn.
4136
host = f"mongodb+srv://{uri['fqdn']}"
37+
else:
38+
# If the fqdn is not present, this is a standard URI and the host and
39+
# port are in the nodelist.
40+
host, port = [f"{node[0]}:{node[1]}" for node in uri["nodelist"]].next().split(":")
4241

4342
settings_dict = {
4443
"ENGINE": "django_mongodb",

0 commit comments

Comments
 (0)