Description
Bug Report
Current Behavior
The opening of a shell does not give the right commands to terminals, namely to cmd
and pwsh
, 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 properly
for 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-bash
environment variables are seemingly set and used correctly: mongo $Env:MDB_CONNECTION_STRING
and mongo $MDB_CONNECTION_STRING
respectively
Expected Behavior/Code
both cmd
and pwsh
connects to the right database succesfuly
Environment
- node.js / npm versions: not relevant
- OS: Windows 10 21H2
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 command
mongo "%MDB_CONNECTION_STRING%"
for pwsh
I think "fixed" issues uses the new powershell
command, but it is for version 5 and above. default powershell executable name is pwsh.exe
. this should be detected and $Env:...
should be used on this shell
mongo $Env:MDB_CONNECTION_STRING
Or the name pwsh
should match as a powershell shell.