In this tutorial, you will learn, how to install MongoDB in MacOS Sierra.
MongoDB is NoSQL database, which uses the document structure to store the data. Simply JSON data format to store the data.
MongoDB comes in two different edition.
1. Community Edition
2. Enterprise Edition
MongoDB community edition is licensed under Apache 2. 0. So we can download and use the community edition for free. For enterprise edition, you have to purchase a license to use.
Download the MongoDB community server using the below link
After downloading the tar(.tgz) file, extract it . I placed the extracted folder in the Desktop and renamed it to mongodb.
You have to include the bin folder to PATH variable using the below command
Note: Replace <mongodb-install-directory> with your full path.
That's all. The setup is completed. To start the MongoDB server, you have to use the below command
mongod --port 27017 --dbpath "/Users/ampersandacademy/Desktop/mdb"
The above command will create a new MongoDB instance under the mdb folder. You can use any location of your choice.
To connect with MongoDB server use the below command in another terminal.
mongo --port 27017
After successful connection, use the below command to get the list of databases available in this newly created MongoDB instance.
By default, admin and local databases are created. If you want to create a new database
The above command will create a new database if the database does not exist or else it connect with that particular database.
Please note that. The above MongoDB instance is not protected with the password.
To import data to the server, you have to use the mongoimport command. To know more about the import, use the below command in terminal