"Launch MongoDB Shell" is not working for cmd
and pwsh
because commands are wrong
#430
Labels
bug
Something isn't working
cmd
and pwsh
because commands are wrong
#430
Bug Report
Current Behavior
The opening of a shell does not give the right commands to terminals, namely to
cmd
andpwsh
, thus either failing or connecting to the wrong database.for
cmd
the issued command is
mongo %MDB_CONNECTION_STRING%
. the problem here is that if the connection string has&
in it, it is considered as part of the terminal's"and then"
logic, thus it does not work properlyfor
pwsh
the issued command is
mongo $MDB_CONNECTION_STRING
. the problem here is that this environment variable is empty for powershell, thus mongo shell tries to connect to localhost. actually, this works on Linux shells but is not how environment variables are accessed in powershell, suggesting this shell is not considered to be a powershell.for
powershell
version 5 and above, and for cygwin-bashenvironment variables are seemingly set and used correctly:
mongo $Env:MDB_CONNECTION_STRING
andmongo $MDB_CONNECTION_STRING
respectivelyExpected Behavior/Code
both
cmd
andpwsh
connects to the right database succesfulyEnvironment
Possible Solution
Although I have found a few closed issues regarding this problem, it seems they fixed only a portion of the problem and failed to test these ones I have found. Fortunately, there is a solution.
for
cmd
the connection string environment variable should be enclosed within quotes. this prevents
&
to leak as terminal commandfor
pwsh
I think "fixed" issues uses the new
powershell
command, but it is for version 5 and above. default powershell executable name ispwsh.exe
. this should be detected and$Env:...
should be used on this shellOr the name
pwsh
should match as a powershell shell.The text was updated successfully, but these errors were encountered: