Installing, starting, and stopping MongoDB under Mac system

Source: Internet
Author: User
Tags install mongodb mongodb server openssl version

I. Download Nodejs, install, until NODE-V displays the version number, indicating that the installation was successful.

Two. This article mainly explains, installs the package way to install MongoDB, as to other way does not introduce.

after downloading MongoDB, copy the mongodb-3.2.5.tar.gz to the/leleda002 path to extract the MongoDB folder, (in which I changed my name and deleted the version number)

The file you just downloaded is not data, etc, and the log folder. There is only one bin folder.

Iii. establishment of documents.

Then create a new data folder in the root directory, and then build a DB folder, that is, in the USR folder above the data folder, which is used to store the database.

Create a new etc folder to put the file configuration.

data/db--and for storing data files, etc--for storing mongod.conf,log--for storing mongod.logs error logs.

Mongod.conf content is as follows

#mongodb config filedbpath=/users/wangxi/documents/mongodb/data/db/logpath=/users/wangxi/ documents/mongodb/true27017truetrue 

This is primarily used to configure the location of the database and the file location of the error output.

Iv. Modifying the system environment variable path

Add the/users/wangxi/documents/develop/mongodb/bin directory to the path.

(In fact, mongodb/bin this address with a shortcut startup directory, find the method of the directory, in the console into the directory, the implementation of PWD can get the directory)

There are many ways to modify environment variables, as follows:

First Add path:

' export Path=/users/wangxi/documents/develop/mongodb/bin: $PATH '

As follows

The shell terminal can be restarted for the environment variable to take effect after the addition is completed

or enter the command source. Bash_profile.

To see if the environment variable was added successfully:

Echo $PATH

As follows:

environment variable added successfully.

4.5. Add operation permissions for database log files.

The newly established DATA/DB needs to add read and write permissions by checking for read and write permissions, if not

sudo chown-r  user name/data/db

V. Start MongoDB

CMD+T Create a new command window, go to MongoDB's "bin" directory, use the command "./mongod" or "Mongod" to start MongoDB server, the last line after successful startup should be the port number, as follows:

This step is connected to the service of MongoDB

Open the browser, enter localhost:27017, and the "

It looks like you is trying to access MongoDB over HTTP on the native driver port.
"Such a line of text, then can reopen a terminal is likewise.

5.5. New window, enter./mongo or MONGO, try to manipulate the database: This step is to operate the database.

The prompt indicates that the connection is successful and a ' > ' symbol is displayed on the terminal, so you can enter MongoDB's SQL command now.

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

Execute in the command window that operates the database

Use Admin;db.shutdownserver ();

  Note: If the installation succeeds, you will only need to start the MongoDB service later, then the gold Operation database will be OK. This is equivalent to just performing the top 5 and 6 steps.

The first 4 steps above are the installation, 56 is to connect the server, start the database.

In connection with the service execution "./mongod" or "Mongod" will often appear some problems, next will I encounter problems in the bottom to do a collation.

First, start the MAC installation Mongoldb error shutting down with code:100.

specific error stack: .-Ten-11t09: to:12.140+0800I CONTROL [Initandlisten] MongoDB starting:pid=2382port=27017dbpath=/data/db --bit host=songyuxiangdemacbook-pro.local .-Ten-11t09: to:12.141+0800I CONTROL [Initandlisten] DB version v3.4.9 .-Ten-11t09: to:12.141+0800I CONTROL [initandlisten] git version:876ebee8c7dd0e2d992f36a848ff4dc50ee6603e .-Ten-11t09: to:12.141+0800I CONTROL [Initandlisten] OpenSSL Version:openssl0.9.8zh -Jan . .-Ten-11t09: to:12.141+0800I CONTROL [Initandlisten] Allocator:system .-Ten-11t09: to:12.141+0800I CONTROL [Initandlisten] Modules:none .-Ten-11t09: to:12.141+0800I CONTROL [Initandlisten] Build environment: .-Ten-11t09: to:12.141+0800I CONTROL [Initandlisten] distarch:x86_64 .-Ten-11t09: to:12.141+0800I CONTROL [Initandlisten] target_arch:x86_64 .-Ten-11t09: to:12.141+0800I CONTROL [Initandlisten] options: {} .-Ten-11t09: to:12.141+0800I STORAGE [Initandlisten] exceptioninchInitandlisten: inData directory/data/db not found., terminating .-Ten-11t09: to:12.141+0800I NETWORK [Initandlisten] shutdown:going to close listening sockets ... .-Ten-11t09: to:12.141+0800I NETWORK [Initandlisten] shutdown:going to flush diaglog ... .-Ten-11t09: to:12.141+0800I CONTROL [Initandlisten] now exiting .-Ten-11t09: to:12.141+0800I CONTROL [Initandlisten] shutting down with code: -

This is a directory-specific issue.

Refer to my startup command.

./mongod--dbpath. /data/db/ starts the MongoDB Shell Client (Command + T). /mongo

Second, the above step 4 environment variable configuration steps.

If there is an error in the configuration of the environment variable, it can also be understood that the path is specified incorrectly, and this time you want to modify or delete

The configuration of the environment variable is understood to be that he wrote the variable in a file.

VI ~/. bash_profile

~/~/~/~/. Bash_profiledd  The code you want to delete, place your cursor in the row you want to  delete, double-click Dd:wq~/.bash_ Profile or close restart shell

After you have finished changing the output, you can see if the changes have been made.

Installing, starting, and stopping MongoDB under Mac system

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: 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.