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