Detailed illustration of mongodb download, installation, configuration and use

Time:2021-12-30

Remember to run CMD in administrator mode, otherwise the service will fail to start.

Detailed illustration, recording the process of installing Mongo database in win7 64. The installed version is mongodb-win32-x86_ 64-2008plus-ssl-3.4. 1-signed。

-Download and install. There are a lot of drawings. I’m not afraid of wordiness, but I’m afraid it’s not enough.

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use
The picture shows what it looked like when it was just installed. There is a typo.

  • Create several folders as follows: database path (data directory), log path (logs directory) and log file (Mongo. Log file)

Note the comparison of folders:

Detailed illustration of mongodb download, installation, configuration and use

  • Create configuration file Mongo Conf, the file contents are as follows:

#Database path
dbpath=D:Mongodata
#Log output file path
logpath=D:Mongologsmongo.log
#The error log is in append mode
logappend=true
#Enable log file, enabled by default
journal=true
#This option can filter out some useless log information. If you need to debug, please set it to false
quiet=true
#The default port number is 27017
port=27017

Detailed illustration of mongodb download, installation, configuration and use

  • Start mongodb service

mongod –config “D:Mongomongo.conf”
This is to start the service using the configuration file you just configured above. Note to change to your own directory location. Well, of course, this is pulled down in the corresponding installation bin directory of the CMD command line window. This is executed under the CMD command line. After execution, there seems to be no big change in the command line. Then you continue to perform the following steps. A screenshot of this step. You can see the command execution effect of this step in step 4 below. You can look at the following step diagram first.

After the command is executed, enter in the browserhttp://127.0.0.1: 27017 when you see the following interface, it indicates that the startup is successful

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use
Some may fail here. Maybe the page is not displayed like this, but it doesn’t matter. You can see whether there are files generated in the data directory and whether there are contents in the log file. If so, the service is started. You can also check whether such a Mongo service exists in the task manager. You can judge whether the service is started or not.

  • Create and start mongodb service
    If you operate as above every time, isn’t it quite troublesome? Create and start the mongodb service according to the following command, and you can manage the startup and shutdown of mongodb through windows service

mongod –config “D:Mongomongo.conf” –install –serviceName “MongoDB”
net start MongoDB
The above is a 2-line command

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use
The startup of this service is a little special. You don’t need login authentication. You can log in without a password. See the figure below for details. This is the effect of logging in with mongovue

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use
Wait a minute, the description on the figure is not very correct. I should have created a database called lxkdb. The other two above are called admin and local, which are automatically generated after Mongo DB is installed.

You can also see that there is no database called test above, so it is wrong to say that the system has a database called test by default. This problem will be explained below.
This sentence was updated later: it is said that this test does not exist or is not completely correct. See the explanation at the bottom for details. Don’t care about this first

The admin database stores user information.
The user information is not as simple as we think, just save a user name and password.
Mongodb does not have permission set by default, that is, it does not have access permission set.
This means that as long as you know the port of the mongodb server, anyone who can access the server can query and operate the contents of the mongodb database.
That is, as I tested above, you can directly test the connection OK without inputting anything.
So: add — auth so that you can use the user name and password in the future before you can perform mongodb related operations
Users and permissions of mongodb are a little complicated. Let’s have an impression first.

There are two kinds of database users, one is administrator, which is used to manage users, and the other is ordinary user, which is used to access data.
(I will continue to talk about how database users with these two permissions are used later)


be careful:

For the following installation service with permission control, don’t adjust it for the time being. If you open this permission, you must first create an account and password in the database.
It’s like you have to prepare the key before locking the lock. Therefore, if you don’t understand this permission, you should not add this permission control for the time being.
Open this permission after you see how to create a new management user and a general database user. I’ll summarize it later.


Explanation of — Security and certification:

The database in each mongodb instance can have many users. If security checking is enabled, only database authenticated users can perform read or write operations.
In the context of authentication, mongodb will process ordinary data as an admin database. Users in the admin database are considered super users (i.e. administrators).
After authentication, the administrator can read and write all databases and execute specific management commands, such as list databases and shutdown.
Before starting the security check, you must have at least one administrator account.

Followed by link:Detailed illustration records examples of win7 64 mongodb’s new manager account and general account

Then, uninstall the service (I will not repeat how to uninstall the service below). Then, if you register a service again, command to add more — auth.

mongod –config “D:Mongomongo.conf” –auth –install –serviceName “MongoDB”
net start MongoDB
You can also add a configuration with auth = true in the configuration file. The effect is almost the same.
Then you can’t log in without a password.

Note: the version of mongovue is too low. Even if your account and password are OK, there will still be exceptions. After I have uninstalled and reinstalled the service for many times, I changed a Mongo database tool. It is OK.
Let’s ignore the error report of this tool for the time being. In the next article, I’ll demonstrate how to use this database. Just know the permission problem here.
And this permission problem is very troublesome.

Detailed illustration of mongodb download, installation, configuration and use
The Mongo service just installed has a default database. Test, user’s name and PWD are all test. See the figure below.

Detailed illustration of mongodb download, installation, configuration and use
Click test to test whether the connection is OK. Then there’s the picture above
Originally, I read someone else’s article that when Mongo was just installed, there was a test database, and then the user name and password were test. Then I tested it with the visualization tool mongovue.
It is found that the test connection is OK, that is, as shown in the figure. Then I thought there was really this database, but then I thought, no, it doesn’t seem to be so.
Later, when I repeatedly tested the permission problem, I found that this mongovue can be tested OK even if you don’t fill in the user name and password, just fill in a database name, and then test the connection.

Detailed illustration of mongodb download, installation, configuration and use
But I don’t have this problem when I use another newly discovered Mongo database tool.

Detailed illustration of mongodb download, installation, configuration and use
Moreover, using the Mongo database tool, you can see that the — auth utility still exists. I haven’t tested it yet. I start the service without permission control, and then log in to the database to see what happens.
I’m free. Or, you can test it. Just before adding — auth to start the service, you can use this tool to connect to the database without using the account password.

The website of this tool is an open source project.
Robomongo 0.9.0
http://blog.robomongo.org/rob…
I downloaded to a cloud disk to share
Link:http://pan.baidu.com/s/1bp8ALDPPassword: iaie

After comparing the two tools, we can find that the version of mongovue is really too low. The next article has the version diagram of this mongovue.

If the mongodb service needs to be uninstalled, it is still in the bin directory,
mongod.exe –remove –serviceName “MongoDB”

Detailed illustration of mongodb download, installation, configuration and use
Then the service is deleted, and then you can’t see the service in the task manager. That means he was killed. Deleted.

If you want to stop this service in the future, right-click, start the task manager, select the above service, and then “service (s)…” in the lower right corner, Then find the system service named mongodb and turn it off

Detailed illustration of mongodb download, installation, configuration and use
At this point, all operations have been completed and the service has been successfully installed.
I will install the Mongo database on my computer for the time being, and how to use it. talk later.

At this time, let’s look at the newly created data folder and Mongo Log files. It can also be explained that the operations along the way are very OK.

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use
Well, hehe, I uploaded a lot of pictures…

Finally, every time you want to use the Mongo command on the command line, you have to enter the corresponding bin directory, which is very troublesome. Why not configure a system environment variable for direct use

Detailed illustration of mongodb download, installation, configuration and use
In this way, it can be used directly on the CMD command line without directory switching

Detailed illustration of mongodb download, installation, configuration and use
Explanation on whether the test database in the database exists or not:

Detailed illustration of mongodb download, installation, configuration and use

Detailed illustration of mongodb download, installation, configuration and use

Turn fromhttp://www.cnblogs.com/sweetc…

Recommended Today

IOS bottom layer exploration: block (V) — block source code analysis (\u what does the bottom layer do?)

review In the previous blog, through theblockTrace the source,Assembly trace mode, source code analysis, on the underlying structure andblockHave a certain understanding of the attributes and methods of, so this blog will continue toblockThe bottom layer of. Block exploration analysis Block of IOS bottom layer exploration (I) — getting to know block (how many blocks […]