MongoDB is a document database which belongs to a family of databases called NoSQL - not only SQL. In MongoDB, records are documents which behave a lot like JSON objects in JavaScript. Values in documents can be looked up by their field’s key. Documents can have some fields/keys and not others, which makes Mongo extremely flexible. This is much different than SQL databases like MySQL, where fields correspond to columns in a table and individual records correspond to rows.
Make sure Homebrew already installed on Mac (Homebrew is a package manager for the Mac – it makes installing most open source software).
Open the Mac terminal application and type brew update, then type brew install mongodb
After MongoDB is downloaded, create a directory to store MongoDB data files, type mkdir -p /data/db
Make sure the directory has the right permissions:
1 | sudo chown -R `id -un` /data/db |
Run the Mongo daemon by typing mongod in your terminal window.
Run the Mongo shell by typing mongo in another terminal window.
To exit the Mongo shell run quit(), to stop the Mongo daemon hit ctrl+c
1) Go to the MongoDB website and download the correct version of MongoDB.
2) After downloading MongoDB, move the gzipped tar file to the folder where you want MongoDB installed by typing commands like these in your terminal:
1 | cd Downloads |
1 | cd ~/ > tar -zxvf mongodb-macos-x86_64-4.2.2.tgz |
4) Create a directory to store MongoDB data files, type mkdir -p /data/db
5) Make sure the directory has the right permissions:
1 | sudo chown -R `id -un` /data/db |
1 | ~/mongodb/bin/mongod --dbpath ~/mongodb/data |
then jump to step 8.
7) Run the Mongo daemon by typing ~/mongodb/bin/mongod in your terminal window.
8) Run the Mongo shell by typing ~/mongodb/bin/mongo in another terminal window.
9) To exit the Mongo shell run quit(), to stop the Mongo daemon hit ctrl+c
MongoDB — Mar 11, 2019
Made with ❤️ and ☀️ on Earth.