Skip to content

Instantly share code, notes, and snippets.

@codev0
Forked from Mikeysax/WSL_Mongo_install.md
Created August 29, 2019 08:50
Show Gist options
  • Save codev0/a429e74dfd025deb483af85c5ea22c46 to your computer and use it in GitHub Desktop.
Save codev0/a429e74dfd025deb483af85c5ea22c46 to your computer and use it in GitHub Desktop.

Install Mongo with WSL for Windows.

Home

This doc will guide you through installing Mongo DB using WSL through the Command Line.

Most of the steps are listed out here, but this guide will trim them down and make it more straight forward for our needs. There is also 1 step that is not in the link above as well, which will be noted when we come across it.

Install MongoDB Community Edition.

  1. Follow the directions listed on the mongodb official website for your distro of choice.

Add the data/db/ directories. NOTE: This step is not included in the link above.

  1. Make sure you are still on the root of the Ubuntu FS by typing cd ~. If you type pwd it should output /home/<user>/
  2. Type mkdir -p data/db
  • This will make a data directory with a db sub directory.
  • The -p flag means make the parent directory if it doesn't exist.

Run mongod server and mongo shell.

  1. Open a new WSL window and type mongod --dbpath ~/data/db.
  • You should see a bunch of stuff pop up, but the last line should be something like waiting for connections on port 27017.
  • This will run your mongod service for you, allowing users to connect to it.
  • The command --dbpath will change the path where mongo saves your databases and records. You can choose your own location if you want, but in the section above we just added it to the root of your Ubuntu File System.
  • Tip: You can add an alias to your .bashrc or .zshrc to make a shortcut for the command in step 1: alias mongostart="mongod --dbpath ~/data/db
  1. Open a new WSL window and type mongo.
  • You should see a connection notification on the first terminal window pop up.
  • In the new window you should see some messages pop up and finally your command line should be changed to a > symbol which means that you are in the mongo shell.
  1. Follow this link to test some commands in your new mongo database.
  2. To exit the shell, press ctrl + c. You should get a neat message, then you'll be returned to your command line!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment