Mr. Gaurav is a cybersecurity engineer, developer, researcher, and Book-Author who did his B.S.-Cybersecurity from EC-Council University & Masters from LPU. He is an India Book of Record holder, Guest speaker with 7+ years of experience in IT.
For enquiries call:
+1-469-442-0620
HomeBlogWeb DevelopmentHow to Install MongoDB on a Mac
MongoDB is one of the most popular unstructured database management systems that can store a high volume of data. It is a document-oriented database system that belongs to the family of NoSQL (non-SQL). Here the data and records are stored as documents that behave more like JSON objects. Documents are a combination of key-value pairs that form the basic unit of data in MongoDB. This database system came into action in mid-2000.
NoSQL stands for Not Only SQL or non-SQL and is an unstructured database that helps store and retrieve data. In the year 1998, Carl Strozz introduced NoSQL. It models the data by means other than the tabular relations. It means such databases do not have a fixed schema, but are intended explicitly for the distributed data that demands humongous data storage. We use NoSQL databases for real-time web apps, mobile apps, big data, etc. Websites like Google, Twitter, Amazon, Facebook, Instagram, etc., collect terabytes of data every day. For more information on web development, check out Full Stack Developer pay after placement.
Earlier, web applications were simple and did not generate such huge amounts of data. But with the advent of big companies like Facebook, Google, Amazon, etc., huge volumes of data are generated, because of which NoSQL databases have become popular. Traditional RDBMS (like SQL) uses simple queries to store and retrieve textual data. But NoSQL database management systems embrace a wide range of file systems storing structured, unstructured, semi-structured, and polymorphic data.
Developers who want to deal with structured, semi-structured, or unstructured data need to use MongoDB for their applications. Those who are into Big data analysis can also use MongoDB. Again, if an application's data needs agility, scaling, and high performance, MongoDB is the best solution.
It supports a broad spectrum of use cases, from real-time exploratory and predictive analytics to parallel data processing. MongoDB can provide high-performance data storage even when spread across multiple servers.
Not sure where to begin your career as a web developer? Enroll in KnowledgeHut training Web Development.
Install Manually without Brew
Step 1: Let us now download MongoDB. For this, open your web browser and type: google.com
Step 2: From Google search, type: MongoDB and hopefully, the first link the search throws up would be the MongoDB link. From here, we have two ways of installing MongoDB. Follow these steps to install using the macOS terminal.
cd Downloads/
ls
tar xzf mongodb-osx-ssl-x86_64-4.4.tgz
sudo mv mongodb-osx-ssl-x86_64-4.4 /usr/local/mongodb
cd /usr/local/mongodb
Next, you have to create the db folder. By default, MongoDB writes or stores the data in the folder called data/db. The command for this will be
sudo mkdir -p /data/db
The -p flag will allow us to create the directory structure. Now, to check whether this path and directory have been created or not, we use the command:
cd /data/db
Now change the permission of this directory. To do this, the command is: sudo chown <user-name> /data/db
If you want to install MongoDB through Homebrew manually, follow these steps –
Step 1: Homebrew helps in installing and managing applications on MacOS. If you haven't downloaded or installed Homebrew, then click the link (https://github.com/mongodb/homebrew-brew) to download the official Homebrew formula for MongoDB, by running the command in your macOS Terminal:
brew update brew tap mongodb/brew
Step 2: Once the Homebrew package resides in your system, you can download MongoDB using brew.
Step 3: Type the following command in your macOS Terminal:
brew install mongodb-community@version-number
Step 4: This installation will add the following binaries:
Step 5: The installation will take a few seconds. Once done, you can create a directory to store MongoDB data using the following command.
sudo mkdir -p /data/db
Step 6: Now, you have to note that your data directory should have the appropriate permissions. To do this, execute the command:
sudo chown -R `id -un` /data/db
Step 7: This will ensure that the data directory is ready and has all the proper permissions.
Step 8: Apart from that, the MongoDB installation will produce the following files and directories at the locations given below –
Intel Processors | Apple M1 | |
---|---|---|
Log directory | /usr/local/var/log/mongodb | /opt/homebrew/var/log/mongodb |
Configuration file | /usr/local/etc/mongod.conf | /opt/homebrew/etc/mongod.conf |
Data directory | /usr/local/var/mongodb | /opt/homebrew/var/mongodb |
Step 9: Let us now run the MongoDB community Edition. You can use the brew command to run MongoDB as a macOS. A manual procedure is needed to run MongoDB services on macOS. To execute MongoDB daemon, which resides by the name mongod (process), use the following command:
brew services start mongodb-community
macOS will run this process as a macOS service.
Step 10: For stopping a mongod process running as a macOS service, apply the following command:
brew services stop mongodb-community
Step 11: For running MongoDB in the background manually and listening for connections on a given port, use the following command -
For Mac systems with Intel processors: mongod --config /usr/local/etc/mongod.conf --fork
For Mac systems with Apple M1 processors: mongod --config /opt/homebrew/etc/mongod.conf –fork
Step 12: Next, verify your MongoDB version. To do this, type the following command: mongo –version
Step 13: The command line will display the installed version of MongoDB on your Mac system. Developers recommend using the newest version of libraries and software whenever feasible. It will keep you away from any compatibility issues with client-side applications.
Step14: You can view the installation list by typing the command: mongodb
Step15: Use the command mongod --config /usr/local/etc/mongod.conf to start the MongoDB
Step 16: To connect to mongodb service, type the command: mongo
Step17: Use the ‘show dbs’ command to see all databases.
You can learn more about the working of MongoDB and become an expert NoSQL database administrator by joining the course mongodb-administrator. This course covers features of MongoDB 4.0 and future releases.
Uninstalling MongoDB from your system will entirely remove MongoDB along with its associated files.
Looking to master Python? Discover the best course for Python programming, designed to unlock your coding potential. Start your journey today!
MongoDB is the leading NoSQL, document-based, open-source database system. It is a cross-platform system - licensed under the Server-Side Public License (SSPL). Due to its broad spectrum of features and benefits, it became popular very quickly. Hopefully, this article has helped you understand the basics of installing MongoDB in your Apple system.
In this article, we have walked you through the two ways to install MongoDB in a macOS. Also, this article explicitly talked about installing MongoDB in Apple systems with Intel processors and with Apple M1 processors. So, you can navigate this article as per your system. You can learn more about MongoDB installation and join the course from mongodb-administrator.
Name | Date | Fee | Know more |
---|