Skip to content

MongoDB Installation

Amos Chua edited this page Mar 13, 2023 · 2 revisions

Setting up a local MongoDB instance for the first time

Follow these steps in order to install MongoDB in the exact same configuration as the test bench for the oauth development branch.


MongoDB Community Edition 6.0

Note: This is the instructions for Windows x64, with the DB server being run on command rather than being available as a background service. This is because such a configuration is better suited for localhost test benches where the servers won't up up for long durations, and are only needed during testing.
Note2: MongoDB does not work with WSL
Note3: MongoDB binds to localhost by default. Remote access requires explicit configuration of bindIp or setting the --bind_ip flag

  1. Download the .msi installer
  2. Run the downloaded installer
  3. Choose the Complete setup (unless you don't have enough free space)
  4. Uncheck Install MongoD as a Service
  5. Install MongoDB Compass (default behaviour; optional)
    • This is so that we can interact with the DB through a GUI interface
    • If you prefer a purely CLI approach, you may skip this and just install MongoDB Shell later
  6. Add C:\Program Files\MongoDB to PATH
    • This is where the server and DB tools reside
  7. Open up your PowerShell profile
    • e.g. code $PROFILE command
  8. Add the following to the end of the file:
    $mongoDirectory = "C:\Program Files\MongoDB\Server\6.0\bin"
    Set-Alias mongod "$mongoDirectory\mongod.exe"
    
  9. Save the file, close and reopen an Administrative PowerShell
  10. Create a folder for the contents of your databases
    • Default data location for the DB is at C:\data\db, so just create this folder if you don't have any preferences
  11. Use the command mongod -h, and you should see a help text in PowerShell
    • You may now start the DB by doing mongod in PowerShell
    • Default data location for the DB is at C:\data\db
    • You may change this behaviour by creating a folder for where you'd like the data to be, then add the followibng flag to mongod for the first run:
      • --dbpath="<FULL/PATH/TO/FOLDER>"

MongoDB Shell 1.8.0

Note: you may need to install this if you chose not to install MongoDB Compass

  1. Download the .msi installer
  2. Run the downloaded installer
    • Note: The .msi installer adds the shell to PATH
    • If you choose the .zip installer instead, you have to manually add the shell to PATH
  3. When MongoDB is running, you may now use mongosh to connect to the DB in command line
    • Just like how we use the command mysql to connect to the DB from the command line

MongoDB Database Tools 100.7.0

Note: This is what we'll be using to flash the sample DB structure for test benches

  1. Download the .msi installer
  2. Run the downloaded installer
  3. Add DB Tools to PATH
    • If you did not change the default install location, you can ignore this step