Home >Operation and Maintenance >Windows Operation and Maintenance >Detailed explanation of mongoDB environment configuration tutorial under windows

Detailed explanation of mongoDB environment configuration tutorial under windows

不言
不言forward
2019-02-28 13:55:463176browse

This article brings you a detailed explanation of the environment configuration tutorial of mongoDB under Windows. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

mongoDB download and installation

Download and install from the official website, you can choose the specific path for installation.

Creating data files and starting

  1. In order to start mongoDB conveniently, we can add the mongo.exe path to the environment variable, Computer->Properties->Advanced System Settings->Environment Variables, add the path to path. In this way, you can use the mongod command everywhere

  2. Create a new mongoDB folder on the D drive to store data files and create data and log folders under it. Create the mongodb.log file in the folder

Start the mongodb service, open the command line and enter

mongod --dbpath "D:\mongodb\data" --logpath "D:\mongodb\log\mongodb.log" --logappend

Enter the command line mongo and the following interface will appear and explain that the installation is successful
* *Analysis: The mongod --dbpath command is to create the storage location of the database file. When starting the mongodb service, you need to determine the storage location of the database file first, otherwise the system will not automatically create it and the startup will be unsuccessful.
--logpath represents the path where the log file is stored
--logappend represents writing the log file in an appended manner **

  1. You need to enter the above command every time you start the service. For convenience, you can write the startup database as a window service.

mongod --dbpath "D:\mongodb\data" --logpath "D:\mongodb\log\mongodb.log" --logappend --directoryperdb --install

After the above steps, we have registered the MongoDB service into the system service. It will be started when the system is turned on, so if we turn it on again, Open cmd as an administrator and enter net start MongoDB. We will be prompted that the service we requested has been started. Therefore, when we turn on the computer next time, we don’t need to do anything. The MongoDB service has already been started, and we can use MongoDB.
Enter the cmd operating environment of mongoDB, and enter the command after all the above configurations are completed. Run mongo to enter, ctrl C is to exit the environment.

Other commands

  • Stop the service
    net stop MongoDB

  • Restart the service
    net restart MongoDB

  • Uninstall the service (stop the service first)

    Note: The path and file name in the above command must still be consistent with those created by yourself, the same below

   mongod --dbpath "D:\mongodb\data" --logpath "D:\mongodb\log\mongodb.log" --logappend --directoryperdb  --remove
  • Reinstallation Service

mongod --dbpath "D:\mongodb\data" --logpath "D:\mongodb\log\mongodb.log" --logappend --directoryperdb  --reinstall

The above is the detailed content of Detailed explanation of mongoDB environment configuration tutorial under windows. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete