Mac installation using MongoDB

Source: Internet
Author: User
Tags brew install mongodb install homebrew install mongodb mkdir mongodb mongodb version

Mac installed MongoDB Generally there are two ways, one is through the source of installation, one is the direct use of homebrew, personal recommendations using homebrew, simple rough.

First, install homebrew:
/usr/bin/ruby-e "$ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install)"
Second, using homebrew to install MongoDB:
Brew Install MongoDB


At this point MongoDB will be installed in/usr/local/cellar/mongodb/4.0.1 (my MongoDB version is 4.0.1), in/usr/local/cellar/mongodb/ 4.0.1 is the implementation of MongoDB files.

(* By default in the Finder is not see/usr this directory (the terminal is used to skip), you can open the Finder and then press SHIFT + Command +g enter/usr/local after the return to see this hidden directory).

After you install MongoDB, you need to configure MongoDB, or you cannot start the server.

Third, configure MongoDB 1. New data/db

Create a new Data folder in the root directory with a DB folder inside it, which is used to store the database (data and USR).

(1) Locate the root directory

CD  /

(2) Create the data/db folder under the root directory:

Mkdir-p/data/db

If permission denied appears, add the sudo command:

sudo mkdir-p/data/db

(3) Give permissions to the/data/db folder:

sudo chown id-u/data/db

If the "Illegal user name" error message appears, we can view the current username and give permission:

/data/db
2. Configure Environment variables

If you don't want to switch to the/usr/local/cellar/mongodb/4.0.1/bin directory every time you start MongoDB, you can add it to the environment variable by doing the following:

  Waiting to be written ...

Four. Start the service side

(1) The terminal switches to the/usr/local/cellar/mongodb/4.0.1/bin directory and executes the Mongod boot server.

When the words waiting for connections on port 27017 appear, our server has started successfully, it is running and listening on port 27017. This allows you to start interacting with the server.

At this point, open the browser, enter localhost:27017, will appear:

V. Connecting the service side

Open a new Terminal tab and run MONGO, which opens the MONGO interactive console and connects to the default server (localhost:27017):

Mongo

To stop MongoDB, be sure to exit correctly, or the next time you connect to the database again, there will be a problem.

> Use admin> Db.shutdownserver ()

  

Mac installation using MongoDB

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.