The installation of mongodb is very simple. The official website provides the download of the installation version and the green version (for those who are slow on the Internet, it is recommended to download them from other channels). My local installation is the installation version, and the directory is the default directory. Let’s not talk about how to install it. Let’s go straight to the topic, first of all, how to start it.
Start up steps:
Method 1: start the service in command line parameter mode
1. Create a data folder under the mongodb installation directory and the directory at the same level as bin. Create a DB in the folder, which is the storage location of the database.
2. Open the DOS interface in the bin directory and enter the command line:
We can see from the startup information that the default port of mongodb is 27017. If we want to change the default startup port, we can specify it through — port. In order to make it easy for us to start each time, we can set the bin directory of the installation directory to the path of the environment variable. Under the bin directory are some common commands, such as mongod to start the service and Mongo to connect the client to the service.
In the printed record, if the on port 27017 command is found, it indicates that the startup is successful.
Method 2: start the service in configuration file mode
1. Create a conf folder under the same level of bin directory, and create a folder named mongod.conf I’m not sure. The contents of the document are as follows:
storage: dbPath: C:\Program Files\MongoDB\Server.0\data\db
It should be noted that fields cannot be divided by tab in the configuration file, otherwise the following error will be reported:
Unrecognized option: dbPath try 'mongod --help' for more information
2. After the configuration file is configured, enter the following command under DOS in bin directory:
mongod -f ../conf/ mongod.conf perhaps
mongod --config ../conf/mongod.conf
In this way, even if mongodb is started successfully, the configuration files are stored according to personal habits, and the location of mongodb is the same. In the learning process, it is recommended to start with the command line. If it is deployed, it must be started with the second way.
After creation, how to connect? First, enter the bin directory of mongodb, open the DOS interface in this directory, and enter the following command to complete the login:
Mongo or Mongo -- host = 127.0.0.1 -- port = 27017
We can see the version information of mongodb
My version is older, and higher versions can display more content:
Use the following command to view:
If the above content appears, the connection is successful.