Install MongoDB on Windows
时间:2022-03-14 00:46
Overview
Use this tutorial to install MongoDB on a Windows systems.
PLATFORM SUPPORT
Starting in version 2.2, MongoDB does not support Windows XP. Please use a more recent version of Windows to use more recent releases of MongoDB.
IMPORTANT
If you are running any edition of Windows Server 2008 R2 or Windows 7, please install .
Install MongoDB
Determine which MongoDB build you need.
There are three builds of MongoDB for Windows:
MongoDB for Windows Server 2008 R2 edition (i.e. 2008R2) runs only on Windows Server 2008 R2, Windows 7 64-bit, and newer versions of Windows. This build takes advantage of recent enhancements to the Windows Platform and cannot operate on older versions of Windows.
MongoDB for Windows 64-bit runs on any 64-bit version of Windows newer than Windows XP, including Windows Server 2008 R2 and Windows 7 64-bit.
MongoDB for Windows 32-bit runs on any 32-bit version of Windows newer than Windows XP. 32-bit versions of MongoDB are only intended for older systems and for use in testing and development systems. 32-bit versions of MongoDB only support databases smaller than 2GB.
To find which version of Windows you are running, enter the following command in the Command Prompt:
wmic os get osarchitecture
Download MongoDB for Windows.
Download the latest production release of MongoDB from the . Ensure you download the correct version of MongoDB for your Windows system. The 64-bit versions of MongoDB does not work with 32-bit Windows.
Install the downloaded file.
In Windows Explorer, locate the downloaded MongoDB msi file, which typically is located in the default Downloads folder. Double-click the msi file. A set of screens will appear to guide you through the installation process.
Move the MongoDB folder to another location (optional).
To move the MongoDB folder, you must issue the move command as an Administrator. For example, to move the folder to C:\mongodb:
Select Start Menu > All Programs > Accessories.
Right-click Command Prompt and select Run as Administrator from the popup menu.
Issue the following commands:
cd move C:\mongodb-win32-* C:\mongodb
MongoDB is self-contained and does not have any other system dependencies. You can run MongoDB from any folder you choose. You may install MongoDB in any folder (e.g.
Modify the path to the mongod.cfg file as needed.
To use an alternate dbpath, specify the path in the configuration file (e.g. C:\ProgramFiles\MongoDB\mongod.cfg) or on the command line with the --dbpath option.
If the dbpath directory does not exist, will not start. The default value for dbpath is\data\db.
If needed, you can install services for multiple instances of or . Install each service with a unique --serviceName and --serviceDisplayName. Use multiple instances only when sufficient system resources exist and your system design requires it.
Stop or remove the MongoDB service as needed.
To stop the MongoDB service use the following command:
net stop MongoDB
To remove the MongoDB service use the following command:
"C:\Program Files\MongoDB\bin\mongod.exe" --remove
Manually Create a Windows Service for MongoDBThe following procedure assumes you have installed MongoDB using the MSI installer, with the default path C:\Program Files\MongoDB 2.6 Standard.
If you have installed in an alternative directory, you will need to adjust the paths as appropriate.
Open an Administrator command prompt.
Windows 7 / Vista / Server 2008 (and R2)
Press Win + R, then type cmd, then press Ctrl + Shift + Enter.
Windows 8
Press Win + X, then press A.
Execute the remaining steps from the Administrator command prompt.
Create directories.
Create directories for your database and log files:
mkdir c:\data\db mkdir c:\data\log
Create a configuration file.
Create a . This file can include any of the for , but must include a valid setting for logpath:
The following creates a configuration file, specifying both the logpath and the dbpath settings in the configuration file:
echo logpath=c:\data\log\mongod.log> "C:\Program Files\MongoDB 2.6 Standard\mongod.cfg" echo dbpath=c:\data\db>> "C:\Program Files\MongoDB 2.6 Standard\mongod.cfg"
Create the MongoDB service.
Create the MongoDB service.
sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB 2.6 Standard\mongod.cfg\"" DisplayName= "MongoDB 2.6 Standard" start= "auto"sc.exe requires a space between “=” and the configuration values (eg “binPath= ”), and a “” to escape double quotes.
If successfully created, the following log message will display:
[SC] CreateService SUCCESS5Start the MongoDB service.
net start MongoDB6Stop or remove the MongoDB service as needed.
To stop the MongoDB service, use the following command:
net stop MongoDBTo remove the MongoDB service, first stop the service and then run the following command:
sc.exe delete MongoDB