mongodb installation

Recently, I am learning the knowledge of mongodb, so I record the process of mongodb learning.

First, the installation of mongodb

1. Go to the official website and find the download address of mongodb https://www.mongodb.com/download-center?jmp=nav#community ,

Since I was studying on a windows computer, I downloaded the windows version.

2. Double-click the downloaded installation package to install it.

3. In the mongodb installation directory, create new data, etc and logs directories

      data directory : used to store mongodb data

      etc directory : used to store the configuration files when mongodb starts

                       Note: The log file specified by logpath must exist in advance, otherwise an error will be reported.

      logs directory : used to store log files

4. In the etc directory above, create a new mongo.cfg file with the following contents

#Database path
dbpath=D:\Program Files\MongoDB\data
#log output file path
logpath=D:\Program Files\MongoDB\logs\mongo.log
#The error log adopts the append mode. After configuring this option, the mongodb log will also be appended to the existing log file instead of re-creating a new file.
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=false
#Port, default is 27017
port=27017

    Among them : D:\Program Files\MongoDB This is the installation directory of my mongodb.

5. Create a new mongo.log file in the logs directory . This file is specified by logpath in the configuration file in the previous step. If this file does not exist, mongodb will report an error when it starts.

6. Enter the bin directory of mongod, mine is the path D:\Program Files\MongoDB\Server\3.4\bin, open the command line window in this, start mongodb, the command is as follows

mongod --config "D:\Program Files\MongoDB\etc\mongo.conf"

    Use --config to specify the configuration file for mongodb to start under Windows

    Use the -f parameter to execute the mongodb configuration file under linux

7. Connect to mongodb, the command is as follows

mongo 127.0.0.1:27017

    The port that mongodb starts by default is 27017, which can be modified in the above configuration file

8. The execution result is as follows

 

9. If you think you have to type a bunch of commands every time you start the server, trouble, you can install mongodb as a windows service

mongod --config "D:\Program Files\MongoDB\etc\mongo.conf" --install --serviceName "MongoDB"

   --serviceName   refers to the name of the installed service 10. Mind map
 of mongodb installation

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326117796&siteId=291194637