MongoDB Installation and Startup
1. Installation
1.1 windows Edition
click https://www.mongodb.com/download-center?jmp=nav#community
Download the msi file on the mongodb official website. Double-click to run it. There is nothing to explain.
1.2 Linux Edition
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.3.tgz # download
tar -zxvf mongodb-linux-x86_64-3.4.3.tgz # decompression
mv mongodb-linux-x86_64-3.4.3/ /usr/local/mongodb
MongoDB executables are located in the bin directory, so they can be added to the PATH path:
export PATH=/usr/local/mongodb/bin:$PATH
1.3 Mac Edition
There are two ways to download the mac version. One is to download the address, just like linux. Here.
The other is through brew installation:
sudo brew install mongodb
If you want to install TLS/SSL support commands as follows:
sudo brew install mongodb --with-openssl
Install the latest development version:
sudo brew install mongodb --devel
2. Start the MongoDB service (take windows as an example)
After installation, the file directory is as follows:
D:\Program Files\MongoDB\Server>tree /a /f
//Folder PATH List
//Volume serial number is 000D-76A0
D:.
\---3.4
| GNU-AGPL-3.0
| MPL-2
| README
| THIRD-PARTY-NOTICES
|
\---bin
bsondump.exe
libeay32.dll
mongo.exe
mongod.exe
mongod.pdb
mongodump.exe
mongoexport.exe
mongofiles.exe
mongoimport.exe
mongooplog.exe
mongoperf.exe
mongorestore.exe
mongos.exe
mongos.pdb
mongostat.exe
mongotop.exe
ssleay32.dll
First, create a folder for storing MongoDB data. I create a folder F: mongodb, then locate it in the bin folder of mongodb and execute the command.
mongod --dbpath=f:\mongodb
The dbpath is used to specify the path to store the data, so the mongodb service starts.
At this time, a new cmd is opened and the shell is opened by entering mongo. In fact, the shell is the client of mongodb and also a compiler of js. The default connection is the "test" database.
D:\Program Files\MongoDB\Server\3.4\bin>mongo
MongoDB shell version v3.4.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.3
> db
test
>
3. Access Control
Note that there is a waring when opening the MongoDB service:
2017-04-05T18:45:08.793+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-04-05T18:45:08.793+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
This is because the access control (authentication, authorization) is not turned on when the service is started. If this warning can be ignored during the learning phase, the production environment needs to turn on access control:
mongod --auth --dbpath=f:\mongodb
Add users (need to operate without opening access control):
use admin
db.createUser(
... {
... user: "test",
... pwd: "test",
... roles: [ { role: "__system", db: "admin" } ]
... }
... )
At this point, use auth to open the service and execute:
db.auth("test","test")
You can continue to operate the database.
4. MongoDb web user interface
MongoDB provides a simple HTTP user interface. If you want to enable this function, you need to specify the parameter - rest at startup.
mongod --dbpath=f:\mongodb --rest
MongoDB's Web interface has 1000 more access ports than the service's.
If your MongoDB runtime port uses the default 27017, you can access the web user interface at port number 28017, i.e. address: http://localhost:28017.