The two days of contact with the MongoDB database, found and MySQL database is still very different, while the configuration before use looks a bit complicated, stepped on a lot of pits, in fact, as long as a step by step to understand, not difficult.
Next, I'll tidy up the entire installation and configuration process.
Installed MongoDB version: Mongodb-win32-x86_64-2008plus-ssl-3.4.10-signed.msi
Computer Information: WIN10 64-bit
First, installation
Installation is actually very simple, all the way next, choose Custom, otherwise cannot continue
I am the default installation location: C:\Program Files\mongodb, you can also choose your own location. After installation is not directly used, need some configuration operations, the next step is to say configuration.
Second, the configuration
Create a MongoDB folder in the C drive (the name can be any, the location can be arbitrary), in this folder to continue the creation of three new folders (name any):
1.data folder: C:\MongoDB\data
2.logs folder: C:\MongoDB\logs, create a new Mongo.log file in this folder
3.etc folder: C:\MongoDB\etc, create a new mongo.conf file in this folder
Finally write the content in the mongo.conf file:
#数据库路径dbpath =c:\mongodb\data# Log output file path logpath=c:\mongodb\logs\mongodb.log# error log with append mode, After configuring this option, MongoDB logs are appended to the existing log file instead of creating a new file logappend=true# enable log file, which is enabled by default journal=true# This option can filter out some useless log information, If debugging is required, set the falsequiet=false# port number to default to 27017port=27017
Note : If the folder you are building is not the same as my location, please modify the address in the file above. The purpose of this file is to be followed. (32-bit may need to add Storageengine=mmapv1, specify storage engine)
Third, start MongoDB
Open cmd as Administrator and enter C:\Program Files\mongodb\server\3.4\bin (depending on the installation directory, to enter the bin directory), such as:
Then enter the command: Mongod--dbpath C:\MongoDB\data
When you see the word "Waiting for connections" on port 27017, it means that the boot is successful, and then you can test it in the browser and enter the localhost:27017
See this diagram to show that the boot was successful. Then open cmd as Administrator again, enter the C:\Program files\mongodb\server\3.4\bin directory, enter the command: MONGO, enter
As shown, you have entered into the MONGO command, where you can perform a series of operations on the database with MONGO commands, such as: Show DBS, view all databases
At this point, how to start the database you have already, but you will find very cumbersome, each time in the bin directory to enter Mongod--dbpath C:\MongoDB\data, it is easy to lose, so now to solve the problem.
Iv. Configuration file Startup
Remember to create a mongo.conf file in the ETC folder, the content of this file is to set some configuration, we can directly through the configuration file to start MongoDB, while installing to the window service.
1. First, go to the bin directory:
CD C:\Program Files\mongodb\server\3.4\bin
2. Enter:
Mongod--config c:\MongoDB\etc\mongo.conf--install--servicename "MongoDB"
Description
--config specify the configuration file;
--install--servicename "MongoDB" is installed into the window service.
At this point, the local service opens, and you can find the MongoDB service and start the service:
In the Bin directory, enter:
net start MongoDB
You're ready to start.
Open the localhost:27017 in the browser to see that the boot is OK. Then, as before, enter MONGO to perform database operations.
If you want to turn off startup, you can enter a command:
net stop MongoDB
Stop service:
Also, if you want to delete the window service, you can enter a command:
Mongod--config c:\MongoDB\etc\mongo.conf--remove
Then go to the service refresh, and found that MongoDB is not.
At this point, you can start MongoDB with the simple net start MongoDB command, but you have to go to the bin directory via the CD C:\Program files\mongodb\server\3.4\bin command before you can execute net s Tart MongoDB. If you do not want to enter the installation directory, you can simplify the operation by adding environment variables.
V. Adding environment variables
1. Go to computer properties and turn on advanced system settings
2. Select advanced options in the Popup box, click the Environment Variables button below
3. Locate path, edit
4. Add the following path; C:\Program Files\mongodb\server\3.4\bin (notice there is a semicolon, can not overwrite the original content, with; delimited), OK.
Add good, what is the benefit of, the advantage is big, at this time to open CMD as an administrator, directly enter the command net start MongoDB, you can start MongoDB, no longer typed into the installation directory.
is not a lot simpler.
Windows detailed MongoDB installation and configuration