Skip to content

Commit a48e325

Browse files
authored
Merge pull request #20 from WaVEV/dbshell
implement dbshell fixes #3
2 parents 2639153 + d983bd5 commit a48e325

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

django_mongodb/client.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,40 @@
44

55

66
class DatabaseClient(BaseDatabaseClient):
7-
executable_name = "mongo"
7+
executable_name = "mongosh"
88

99
@classmethod
10-
def settings_to_cmd_args_env(cls, settings_dict, parameters):
11-
raise NotImplementedError
10+
def settings_to_cmd_args_env(cls, settings_dict, parameters): # noqa: ARG003 parameters unused
11+
options = settings_dict.get("OPTIONS", {})
12+
args = [cls.executable_name]
13+
14+
host = settings_dict["HOST"]
15+
port = settings_dict["PORT"]
16+
dbname = settings_dict["NAME"]
17+
user = settings_dict["USER"]
18+
passwd = settings_dict["PASSWORD"]
19+
auth_database = options.get("authSource")
20+
auth_mechanism = options.get("authMechanism")
21+
retry_writes = options.get("retryWrites")
22+
23+
if host:
24+
args += ["--host", host]
25+
if port:
26+
args += ["--port", port]
27+
if user:
28+
args += ["--username", user]
29+
if passwd:
30+
args += ["--password", passwd]
31+
if auth_database:
32+
args += ["--authenticationDatabase", auth_database]
33+
if auth_mechanism:
34+
args += ["--authenticationMechanism", auth_mechanism]
35+
if retry_writes is not None:
36+
args += ["--retryWrites", str(retry_writes).lower()]
37+
38+
args.append(dbname)
39+
40+
return args, None
1241

1342
def runshell(self, parameters):
1443
sigint_handler = signal.getsignal(signal.SIGINT)

0 commit comments

Comments
 (0)