Mongodb starts the client and briefly demonstrates switching databases

The above window downloads and installs the Mongodb database. We simply set up the Mongodb service
, but we also need a client.

Let’s start the server

mongod --dbpath=..\data\db

Insert image description here

We then run a terminal as an administrator and
directly enter the bin of the Mongodb installation directory
Insert image description here
. Then the command to start the client is mongo --host service ip --port service port.
The default is

mongo --host localhost --port 27017

Access port 27017 of this machine.
If you want to use this directly

mongo

It is also possible
, but the mongo command is no longer provided after MongoDB 4.4.
If it is a version after MongoDB 4.4, you can check my article to solve the problem that there is no mongo.exe file in the downloaded MongoDB bin directory.

Mongodb also has the concept of library.
Insert image description here
According to the console output, we are currently under the test library
and we can enter

show dbs

It will output all the libraries we think of except the current database.
Insert image description here
For example, if we want to enter the admin database, we can enter

use admin

In this way, we are currently in the admin database.
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_45966674/article/details/135368216