Integrate mongo shell [mongosh] in Windows Terminal | Easy
I like Windows Terminal a lot, especially its customization features. By changing its settings.json file one can customize the terminal according to one's taste.
Earlier; to connect mongo shell i.e. mongosh with a MongoDB instance one had to to type the command mongosh "mongodb://<username:password>@<mongodb-instance>/<database-name>"
in CMD
or Powershell
.
For this command to work you need to add mongosh.exe
to path variable in Windows. You can find an article here which goes in detail how to do that.
To integrate mongosh with Windows Terminal
Step1: Open Windows Terminal
Type 'windows terminal' in the search bar located in the Windows taskbar and click on Windows Terminal option.
Step 2: Open settings.json
Open settings.json by clicking on the down arrow besides the +
tab and clicking on settings
. Alternatively, you can use Ctrl + ,
keyboard shortcut as well.
Step3: Edit settings
I have bound json files to open with Visual Studio Code you can use any text editor. Now copy the powershell
profile and paste it below it, as shown below.
And change it like this (or you can copy it as it is from below and paste it in your file):
Save and see the changes.
Now whenever you want to open the mongo shell:
Open Windows terminal > click on the drop down > click on Mongo Shell and you have a connected shell. No need to remember the connection string and no hassle to type it again and again.
If you have multiple mongo instances running, you can replicate the steps above and have multiple quick connect tabs available in the Windows terminal.
Hope this article is of any help. Thanks for reading.