MongoDB study notes (1)-installation and configuration

1 Introduction

MongoDB is written in C++ and is an open source database system based on distributed file storage, which is a non-relational database (NoSQL).

Features :

Development is fast, minimalist and flexible, document-oriented (file storage format is BSON, an extension of JSON)

Three concepts:

  • Database: data warehouse, can store collections
  • Collection: can store documents
  • Document: the smallest unit

2. Download

MongoDB provides pre-compiled binary packages for 32-bit and 64-bit systems. You can download and install it from the MongoDB official website. The MongoDB pre-compiled binary package download address: https://www.mongodb.com/download-center#community

Note: Windows XP system is no longer supported after MongoDB version 2.2. The latest version also has no installation files for 32-bit systems.


3. Installation

Download the 32-bit or 64-bit .msi file according to your system, double-click the file after downloading, and install it as prompted.

I actually installed the 4.0 version of the program, and the following takes the installation steps of the 3.6 version of the program as an example:


4. Configuration

Note: If you are using a version above 4.0 , there will be a step during the installation that allows us to customize the Data and Log paths. You should skip sections 1)2)3) and proceed directly to the local service configuration in section 4).

1) Create a storage location for MongoDB database files

Create a path in the root directory of the installation disk : C :\mongodb\data

Because the database file storage folder must be created before starting the mongodb service, otherwise the command will not be created automatically, and the startup cannot be successful.

2) Create MongoDB startup configuration file

In M ongoDB new installation configuration file path mongo.config, as follows:

systemLog:
     destination: file
     path: C:\mongodb\mongod.log
     logAppend: true
security:
     authorization: enabled
storage:
     dbPath: C:\mongodb\data
     directoryPerDB: true
net:
     bindIp: 127.0.0.1
     port: 27017

3) Configure the local windows MongoDB service

Set MongoDB as a system service, which can be automatically started in the background, and does not need to be started manually every time.

When configuring windows services, you need to run the CMD command line tool as an administrator . Find the cmd running file under the system path C:\Windows\System32 , and run the CMD command. Or directly search for the program, enter cmd, right-click and select ==> Run as administrator.

Run the following command to enter the bin directory:

cd C:\Program Files\MongoDB\Server\4.0\bin

Run the following command to configure the windows service:

mongod --config "C:\Program Files\MongoDB\Server\4.0\mongo.config" --install --serviceName "MongoDB"

After completion, check the local service, if successful, you will find that the local service has more "MongoDB" services.

You can start the service by right-clicking the MongoDB service and selecting Start, or you can enter the following command on the command line to start:

net start MongoDB

At the same time, commands to shut down and remove services are given. Shut down the MongoDB service:

net stop MongoDB

Remove the MongoDB service:

C:\mongodb\bin\mongod.exe --remove

4) Configuration above 4.0

For version 4.0 and above, the config file is in the bin directory

Just open and modify #security as follows, pay attention to the indentation:

security:
  authorization: enabled

Refer to section 3), run cmd as an administrator, and enter the following commands in sequence to configure windows services:

cd C:\Program Files\MongoDB\Server\4.0\bin

mongod --config "C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg" --install --serviceName "MongoDB"

5) Check whether the startup is successful

Enter http://localhost:27017 (27017 is the port number of mongodb) in the browser to view. If the following display is displayed, the connection is successful.

If it is unsuccessful, you can check whether the port is occupied.

 

Guess you like

Origin blog.csdn.net/qq_14997473/article/details/89601225