Setting Up MongoDB
There are a number of things you must do before study compass is ready to run on your machine. Make sure you have asked James for the .env
file, as that will be necessary for starting the setup.
Before following the steps in this tutorial, make sure you have the necessary tools installed. If you're not sure, you can check by running all the following commands in powershell or zsh:
mongodump
mongorestore
mongod
If any of the above commands cause errors, you do not have the necessary tools installed.
Step 1: Download and Install Mongo Community Server and Tools
If you have all the necessary tools installed, you can skip this step.
Install MongoDB Community Server:
-
Download Community Server: Download the Community Server from the MongoDB website, I would recommend downloading as msi. Make sure to run the msi after download. This step may take a few minutes, and will download the community server as well as the
MongoDBCompass
application. -
Locate MongoDB Bin: Locate the
bin
directory inside your MongoDB installation directory. For example, it might beC:\Program Files\MongoDB\Server\<version>\bin
. MongoDB might also be insideProgram Files (x86)
-
Add To Path: Open Environment Variables, select
Path
underSystem Variables
, clickEdit
, and add the bin path as a new variable. -
Verify Installation: To verify that the installation has been executed directly, restart powershell, and run the following command:
mongod
This action should not cause any errors.
Install MongoDB Tools
- Download Mongo Tools:
Dowlnoad the Mongo Tools from the MongoDB website. I would recommend downnloading as msi. This should install the
mongodump
andmongorestore
executables. - Locate Mongo Tools Bin:
Locate the
bin
directory inside your MongoDB installation directory. For example, it might beC:\Program Files\MongoDB\Tools\bin
. Mongo Tools might also be insideProgram Files (x86)
. - Add to Path: Reference above steps, add the bin path.
- Verify Installation
To verify that the installation has been executed directly, restart powershell, and run the following command:
This action should not cause any errors. You may have to halt the execution of the commands (this is normal and means that the tools have been installed correctly).
mongodump
mongorestore
Step 2: Export the MongoDB Atlas Database
First, you need to export your MongoDB Atlas database to a BSON (Binary JSON) file. You can use the mongodump
tool for this. Make sure you have your own Mongo Atlas URL (should be given by James)
-
Export the Database: Use
mongodump
to export your database. You need your MongoDB Atlas connection string, which you can find in the Atlas UI.mongodump --uri="your-atlas-connection-string" --out=/path/to/dump
noteYour path to dump is just a temporary storage location so the location isn't very important. A good example would be
C:\Users\<usename>\dump
Replace
your-atlas-connection-string
with your actual connection string and/path/to/dump
with the path where you want to save the dump files.
Step 3: Import the Dump into Your Local MongoDB Instance
Next, you need to import the BSON files into your local MongoDB instance.
-
Import the Database: Use
mongorestore
to import the BSON files into your local MongoDB.mongorestore --db studycompass /path/to/dump/studycompass
noteFor the mongorestore path, just take your dump path and add
studycompass
at the end. For example, if my dump path wasC:\Users\James\dump
, the monogrestore path would beC:\Users\James\dump\studycompass
Replace
your-local-db-name
with the name you want for your local database,/path/to/dump
with the path to the dump files, andyour-atlas-db-name
with the name of the database from MongoDB Atlas.
Step 4: Verifying Database
Open the MongoDBCompass App, click connect. Under Databases, if you see the studycompass
database, the database has been installed correctly.