JIYIK CN >

Current Location:Home > Learning > DATABASE > MongoDB >

Install MongoDB using Homebrew

Author:JIYIK Last Updated:2025/04/29 Views:

MongoDB is a well-known unstructured database management system that can handle large amounts of data. It is a document-oriented database system and belongs to the NoSQL family (non-SQL).

Data and records are stored as documents that look and function like JSON objects. A document is a collection of key-value pairs that make up the basic unit of data in MongoDB.

The database system was implemented in the mid-2000s.

Developers who want to process organized, semi-structured, or unstructured data in their applications need MongoDB. People who are interested in big data analysis can also use MongoDB.

If your application's data requires agility, scalability, and high performance, MongoDB is the best choice.

It supports a wide range of applications, including real-time exploratory and predictive analytics and parallel data processing. In addition, MongoDB provides high-performance data storage even when spread across many servers.

There are two ways to install MongoDB on your MAC. One without Homebrew and the second with Homebrew.

To install via macOS Terminal, follow the steps below.

  1. Let's install MongoDB. To do this, open your browser and put google.com into the address bar.
  2. Type MongoDB into Google search and ideally the first link that comes up is the MongoDB link. From here you have two options for installing MongoDB.
  3. Head over to the MongoDB Community to learn more. Next, choose the version, platform, and package you want to use.
  4. After selecting macOS as the platform, click the Download button and tgz as the file format.
  5. After downloading the tgz file, unzip it using the macOS Terminal.
  6. Your MongoDB will most likely be downloaded to the Downloads folder. To do this, open the MongoDB terminal and write this command.
    sudo mv mongodb-osx-ssl-x86_64-4.4.1 /usr/local/mongodb
    
  7. You have to move the MongoDB folder to local binary storage.
    sudo mv mongodb-osx-ssl-x86_64-4.4.1 /usr/local/mongodb
    
  8. This will ask for your system password. Provide the password.
  9. You can change directory to /usr/local/mongodb and use the ls command to see if all the files are there. Note that this step is optional.
  10. To change directory, type the following command.
    cd /usr/local/mongodb
    
  11. After that, you have to create the database folder. MongoDB writes or stores data in the data/db subdirectory by default.
  12. So that would be its command.
    sudo mkdir -p /data/db
    
  13. You can use the -p parameter to create the directory structure. For example, use the following command to see if this path and directory have been created.
    cd /data/db
    
  14. To check if you are in the correct directory, enter the command: pwd. To change permissions, you must first know your login name.
  15. Type the command whoami to find out your username.
  16. Now change the permissions of the directory. The command to do this is:
    sudo chown /data/db
    

Install MongoDB using Homebrew

If you prefer to install MongoDB using Homebrew, follow these instructions manually.

  1. On macOS, Homebrew helps install and manage programs.
    brew update
    brew tap mongodb/brew
    
  2. After the Homebrew package is installed, you can use brew to download MongoDB.
  3. In your macOS Terminal, type the following command.
    brew install mongodb-community@version-number
    
  4. The following binaries are installed as part of this installation.
  • mongod server
  • mongo shell
  • mongos sharded cluster query routing
  1. It will take a few seconds to complete the installation. After that, create a directory to store MongoDB data using the following command.
    sudo mkdir -p /data/db
    
  2. At this point, you must ensure that your data directory has the appropriate permissions. To do this, use the following command.
    sudo chown -R id -un /data/db
    
  3. This ensures that the data directory is ready and has the appropriate permissions. For example, the MongoDB installation will create the following files and folders in the following location.
apple M1 Intel processors
Log Directory /opt/homebrew/var/log/mongodb /usr/local/var/log/mongodb
Configuration Files /opt/homebrew/etc/mongod.conf /usr/local/etc/mongod.conf
Data Catalog /opt/homebrew/var/mongodb /usr/local/var/mongodb
  1. Now, you will use MongoDB Community Edition. MongoDB can be started on macOS using the brew command.
    However, the MongoDB service on macOS requires manual operation. Use the following command to run the MongoDB daemon, called mongod (process).

    brew services start mongodb-community
    

    This process will be performed by macOS as a macOS service.

  2. Use the following command to kill the mongod process operating as a macOS service.

    brew services stop mongodb-community
    
  3. To manually start MongoDB in the background and listen for connections on a specific port, use the following command:

  • mongod -config /usr/local/etc/mongod.conf -fork for Macs with Intel CPUs.
  • mongod -config /opt/homebrew/etc/mongod.conf –fork is for Macs with Apple M1 CPUs.
  1. Finally, check your MongoDB version again. Type the following command: mongo –versionis a command that can be used to change the version.
    The command line will show you the MongoDB version installed on your Mac. If possible, the developers recommend using the latest version of libraries and applications.
    Also, it will keep you safe from client application compatibility issues.
  2. Enter the command mongodb to display the installation list.
  3. mongod -config /usr/local/etc/mongod.confStart MongoDB using the command .
  4. Type the following command to connect to the MongoDB service: mongo.
  5. To display all databases, use show dbsthe command.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

List all collections in MongoDB Shell

Publish Date:2025/04/29 Views:156 Category:MongoDB

When using MongoDB , there are several ways to list the collections in the database. This article will discuss four different ways to get a list of collections in a MongoDB database. These methods are as follows: show collections List all c

Querying for non-null values in MongoDB

Publish Date:2025/04/29 Views:139 Category:MongoDB

This MongoDB article will explain how to query for non-null values ​​in MongoDB. To query for non-null values, you can use $ne the operator and $eq the operator and then specify the desired value to query. This article shows the readers

Shutting down with code:100 error in MongoDB

Publish Date:2025/04/29 Views:53 Category:MongoDB

This MongoDB tutorial will teach you to fix the error on different operating systems shutting down with code:100 . It will also talk about the root cause of why this issue occurs. shutting down with code:100 Errors in MongoDB As we all know

SELECT COUNT GROUP BY in MongoDB

Publish Date:2025/04/29 Views:74 Category:MongoDB

In this article, we will discuss the functions in MongoDB. Also, we will point out the aggregation functions in detail. We will explain in detail the different ways to count and sort multiple and single fields of Group in MongoDB. Operation

Differences between MongoDB and Mongoose

Publish Date:2025/04/29 Views:80 Category:MongoDB

This MongoDB article will discuss the differences between MongoDB and Mongoose. Unfortunately, most beginners tend to confuse these two concepts when they start developing applications and use MongoDB as their backend. MongoDB has its own s

Use find operator to join multiple conditions in MongoDB

Publish Date:2025/04/29 Views:132 Category:MongoDB

$lookup Today, we will see how to concatenate multiple conditions using the operator in MongoDB . In addition, we will explore some examples to demonstrate the use of $group the stage and $unionWidth the aggregation stage. $lookup Use the o

Date comparison in MongoDB

Publish Date:2025/04/28 Views:170 Category:MongoDB

This MongoDB tutorial discusses the issue of returning Date-based queries. In addition, there is also a good tutorial on how to use Date Range queries in MongoDB. Using date ranges in MongoDB We will learn to write MongoDB date range querie

Find objects between two dates in MongoDB

Publish Date:2025/04/28 Views:95 Category:MongoDB

In this article, the problem of finding objects between two dates was briefly discussed. In addition, the operators $gte, $lte, $gt, and $lt used for this purpose were briefly explained in detail. Querying date ranges in MongoDB This sectio

Comparing Dates in MongoDB

Publish Date:2025/04/28 Views:115 Category:MongoDB

Date is a common field in most databases, and sometimes we need to find exact documents from a collection in MongoDB. For example, if we have a collection of orders, we might search for those documents before or after a specific date. In th

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial