Meteor + MongoDB Local Setup on Mac
Creating builds for a meteor app using a remote (hosted) database can be time-consuming because of the long compile time. It is more efficient to develop locally. As a solution to this problem, I did my research and drew knowledge from various sources to get this article compiled. I decided I should share it! If you believe it could be improved upon, please don't fail to leave a comment below.
Step 1 *optional*: Clone your online MongoDB database if you have one
This can be done online using the mLab user interface. However, this comes at a cost of about $0.50 per backup. After the backup is complete, manually download the zip file and unzip.
Step 2: Installing MongoDB locally on Mac
2.1 Open the Terminal app and run the command $ brew update to update Homebrew.
2.2 Run the command $ brew install mongodb to install mongodb locally.
2.3 Create the “db” directory. This is where the Mongo data files will live. You can create the directory in the default location by running $ mkdir -p /data/db
2.4 Make sure that the /data/db directory has the right permissions by running
> sudo chown -R `id -un` /data/db
> # Enter your password
2.5 Run the Mongo daemon in one of your terminal windows. To achieve this, run the command $ mongod. This should start the Mongo server.
2.6 Run the Mongo shell, with the Mongo daemon running in one terminal, run the command mongo in another terminal window. This will run the Mongo shell which is an application to access data in MongoDB.
Step 3: Import database to local mongodb
Open a new terminal window
Run the command $ mongorestore -d database_name downloads/….(.....should be the right path to the folder where the downloaded backup from step 1 is. Make sure you unzip the downloaded file and navigate to the folder actually containing the BSON files)
Step 4: View mongodb documents via a GUI
Download and install Robo 3T on your mac
Step 5: Start MongoDB locally
Before you can use the local mongo instance with your meteor application, make sure you start MongoDB first with the terminal command as shown in step 2.5. To achieve this, run the command $ sudo mongod.Optionally, You can open up the mongo shell with the terminal command $ mongo.
Step 6: Start your meteor application locally
Navigate to the folder containing you meteor application in the terminal
Run MONGO_URL='mongodb://localhost:27017/database_name’ meteor inside the meteor app folder