Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Launch MongoDB Shell" is not working for cmd and pwsh because commands are wrong #430

Open
yilmazdurmaz opened this issue Jul 17, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@yilmazdurmaz
Copy link

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.

@mmarcon mmarcon added the bug Something isn't working label Nov 21, 2022
@alenakhineika
Copy link
Contributor

Thank you for opening the issue! Created a ticket to track progress: https://jira.mongodb.org/browse/VSCODE-351

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants