MongoDB installation and configuration tutorial (detailed version)

Preface: MongoDB is a database commonly used by front-end developers, because MongoDB does not require a graphical interface and is an open source database system based on distributed file storage. MongoDB stores data as a document, and the data structure consists of key-value pairs (key=>value); MongoDB documents are similar to JSON objects.

Sign of successful installation:

1. Open the server and enter the address: 'http://localhost:27017';
2. The information displayed on the page is: 'It looks like you are trying to access MongoDB over HTTP on the native driver port.'

Next start the installation:

1. Download the MongoDB database address: (the computer version will be automatically detected, and the appropriate MongoDB version number will be downloaded)

https://www.mongodb.com/try/download/community

2. Open the downloaded file, find the msi suffix and double-click to enter the installation

3. Custom can specify that you want to install it on the D drive or other drives

  3. Default 'Run service as Network Service user'

4. Uncheck the graphical tool (Install MongoDB Compass) in the lower left corner , otherwise the installation time will be very long...

5. Click next, finish will end the installation

6. The folder directory after installation, the config file is added later, will be introduced later

 Now start to configure the database environment of MongoDB

1. Right-click the desktop icon "My Computer" , find  the environment variable, find path in the system variable , and click Edit

 2. Add the bin address of MongoDB (ps: pay attention to the folder path where mongodb is stored on your computer)

 The last step is to run the MongoDB service

 1. Create the storage location of the database file

Create a db folder under the data folder (before starting the MongoDB service, you must create a storage folder for the database file, otherwise the command will not be created automatically, and the startup cannot be successful)

 

 2. Start the MongoDB service (Win+R key), enter cmd

 3. Enter the command editing mode, find the db file, and enter it as follows

 4. Enter the command to start the MongoDB service

mongod   --dbpath D:\MyApp\Mongodb\Server\data\db

5. After pressing the Enter key, it is displayed that the general port is 27017

 6. Enter the address and port number in the browser as:

http://localhost:27017

7. The display results are as follows, which means that the installation is successful and ends

8. Press 'Ctrl + C'  twice to end the process

Then configure the local Windows MongoGB service

In this way, it can be set to start automatically at boot, and it can be manually started and closed directly. It can be started through the command line net start MongoDB, and there is no need to enter the bin directory to start it;

1. Create a new folder log under the data file (used to store log files)

 2. Create a new configuration file mongo.config in MongoGB, open and edit it with Notepad

Input: (ps: subject to your actual installed file address)

dbpath=D:\MyApp\Mongodb\Server\data\db
logpath=D:\MyApp\Mongodb\Server\data\log\mongo.log
#数据库数据存放目录
dbpath=D:\MyApp\Mongodb\Server\data\db
#数据库日志存放目录
logpath=D:\MyApp\Mongodb\Server\data\log\mongo.log
#以追加的方式记录日志
logappend = true
#端口号 默认为 27017
port=27017

#开启用户认证
auth=false
#mongodb所绑定的ip地址,绑定后只能通过127访问
bind_ip = 0.0.0.0

#启用日志,默认启用
journal=true
#过滤掉一些无用的日志信息,若需要调试使用请设置为false
quiet=true
#不允许全表扫描
notablescan=false

 

 3. Open cmd as an administrator , and find the bin file address: "D:\MyApp\Mongodb\Server\bin '', and enter the code: mongod -dbpath "D:\MyApp\Mongodb\Server\data\ db" -logpath "D:\MyApp\Mongodb\Server\data\log\mongo.log" -install -serviceName "MongoDB";

'MongoDB' is the name of the MongoDB service that will be started later

 4. Start and shut down the MongoDB service in the cmd administrator

(1) The command to start MongoDB is:net start MongoDB

(2) Enter the address and port number in the browser : http://localhost:27017, the display is as follows, indicating that the MongoDB service has been started

 5. To start MongoDB, press Win+R to enter services.msc to determine whether it is started

 6. The command to close MongoDB is:net stop MongoDB  查看启动的网页没有显示英文了就表示已经关闭了。

Guess you like

Origin blog.csdn.net/qq_45790877/article/details/129286309