Install MongoDB Community Edition on Windows
網上關於安裝MongoDB的中文介紹坑太多,請參考下面的官方文件,原文地址
Overview
Use this tutorial to install MongoDB Community Edition on 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 a hotfix to resolve an issue with memory mapped files on Windows.
Requirements
MongoDB Community Edition requires Windows Server 2008 R2, Windows Vista, or later. The .msi installer includes all other software dependencies and will automatically upgrade any older version of MongoDB installed using an .msi file.
Get MongoDB Community Edition
Determine which MongoDB build you need.
There are three builds of MongoDB for Windows:
MongoDB for Windows 64-bit 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 32-bit runs on any 32-bit version of Windows newer than Windows Vista. 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.
NOTE
Starting in MongoDB 3.2, 32-bit binaries are deprecated and will be unavailable in future releases.
MongoDB for Windows 64-bit Legacy runs on Windows Vista, Windows Server 2003, and Windows Server 2008 and does not include recent performance enhancements.
To find which version of Windows you are running, enter the following commands in the Command Prompt or Powershell:
wmic os get caption
wmic os get osarchitecture
Download MongoDB for Windows.
Download the latest production release of MongoDB from the MongoDB downloads page. Ensure you download the correct version of MongoDB for your Windows system. The 64-bit versions of MongoDB do not work with 32-bit Windows.
Install MongoDB Community Edition
Interactive Installation
Install MongoDB for Windows.
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.
You may specify an installation directory if you choose the “Custom” installation option.
NOTE
These instructions assume that you have installed MongoDB to 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. D:\test\mongodb).
Unattended Installation
You may install MongoDB Community unattended on Windows from the command line using msiexec.exe.
Open an Administrator command prompt.
Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Administrator.
Execute the remaining steps from the Administrator command prompt.
Install MongoDB for Windows.
Change to the directory containing the .msi installation binary of your choice and invoke:
msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.2.1-signed.msi ^
INSTALLLOCATION="C:\mongodb" ^
ADDLOCAL="all"
You can specify the installation location for the executable by modifying the INSTALLLOCATION value.
By default, this method installs all MongoDB binaries. To install specific MongoDB component sets, you can specify them in the ADDLOCAL argument using a comma-separated list including one or more of the following component sets:
Component Set | Binaries |
Server | mongod.exe |
Router | mongos.exe |
Client | mongo.exe |
MonitoringTools | mongostat.exe, mongotop.exe |
ImportExportTools | mongodump.exe, mongorestore.exe, mongoexport.exe, mongoimport.exe |
MiscellaneousTools | bsondump.exe, mongofiles.exe, mongooplog.exe, mongoperf.exe |
For instance, to install only the MongoDB utilities, invoke:
msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.2.1-signed.msi ^
INSTALLLOCATION="C:\mongodb" ^
ADDLOCAL="MonitoringTools,ImportExportTools,MiscellaneousTools"
Run MongoDB Community Edition
WARNING
Do not make mongod.exe visible on public networks without running in “Secure Mode” with the authsetting. MongoDB is designed to be run in trusted environments, and the database does not enable “Secure Mode” by default.
Set up the MongoDB environment.
MongoDB requires a data directory to store all data. MongoDB’s default data directory path is\data\db. Create this folder using the following commands from a Command Prompt:
md \data\db
You can specify an alternate path for data files using the --dbpath option to mongod.exe, for example:
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data
If your path includes spaces, enclose the entire path in double quotes, for example:
C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"
You may also specify the dbpath in a configuration file.
Start MongoDB.
To start MongoDB, run mongod.exe. For example, from the Command Prompt:
C:\mongodb\bin\mongod.exe
This starts the main MongoDB database process. The waiting for connections message in the console output indicates that the mongod.exe process is running successfully.
Depending on the security level of your system, Windows may pop up a Security Alert dialog box about blocking “some features” of C:\mongodb\bin\mongod.exe from communicating on networks. All users should select Private Networks, such as my home or worknetwork and click Allow access. For additional information on security and MongoDB, please see the Security Documentation.
Connect to MongoDB.
To connect to MongoDB through the mongo.exe shell, open another Command Prompt.
C:\mongodb\bin\mongo.exe
If you want to develop applications using .NET, see the documentation of C# and MongoDB for more information.
Begin using MongoDB.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. See Getting Started for the available editions.
Before deploying MongoDB in a production environment, consider the Production Notes document.
Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.
Configure a Windows Service for MongoDB Community Edition
Open an Administrator command prompt.
Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Administrator.
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 configuration file. The file must set systemLog.path. Include additional configuration options as appropriate.
For example, create a file at C:\mongodb\mongod.cfg that specifies both systemLog.path andstorage.dbPath:
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
Install the MongoDB service.
IMPORTANT
Run all of the following commands in Command Prompt with “Administrative Privileges”.
Install the MongoDB service by starting mongod.exe with the --install option and the -configoption to specify the previously created configuration file.
"C:\mongodb\bin\mongod.exe" --config "C:\mongodb\mongod.cfg" --install
To use an alternate dbpath, specify the path in the configuration file (e.g.C:\mongodb\mongod.cfg) or on the command line with the --dbpath option.
If needed, you can install services for multiple instances of mongod.exe or mongos.exe. Install each service with a unique --serviceName and --serviceDisplayName. Use multiple instances only when sufficient system resources exist and your system design requires it.
Start the MongoDB service.
net start MongoDB
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:\mongodb\bin\mongod.exe" --remove
Manually Create a Windows Service for MongoDB Community Edition
You can set up the MongoDB server as a Windows Service that starts automatically at boot time.
The following procedure assumes you have installed MongoDB Community using the .msi installer with the path C:\mongodb\.
If you have installed in an alternative directory, you will need to adjust the paths as appropriate.
Open an Administrator command prompt.
Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Administrator.
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 configuration file. The file must set systemLog.path. Include additional configuration options as appropriate.
For example, create a file at C:\mongodb\mongod.cfg that specifies both systemLog.path andstorage.dbPath:
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
Create the MongoDB service.
Create the MongoDB service.
sc.exe create MongoDB binPath= "C:\mongodb\bin\mongod.exe --service --config=\"C:\mongodb\mongod.cfg\"" DisplayName= "MongoDB" 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 SUCCESS
Start the MongoDB service.
net start MongoDB
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, first stop the service and then run the following command:
sc.exe delete MongoDB
Additional Resources¶
相關文章
- install mongodb on macosMongoDBMac
- 微軟Windows Community Toolkit一覽微軟WindowsUnity
- IDEA社群版(IDEA Community Edition)建立Springboot父子專案IdeaUnitySpring Boot
- 將 Server Community Edition 應用程式方便地遷移到 WebSphere Application ServerServerUnityWebAPP
- 從 JBoss v4.x 遷移到 IBM WAS Community Edition v2.xIBMUnity
- MobaSSH SSH server for Windows - Download Home EditionServerWindows
- 為 WebSphere Application Server Community Edition V2.1 構建 WADI 叢集環境WebAPPServerUnity
- Mysql 5.7.22 install for windowsMySqlWindows
- Install Tensorflow on windows(Anaconda)Windows
- /****install oracle patch 9169457 for windows****/OracleWindows
- oracle communityOracleUnity
- Community ServerUnityServer
- SQL Server 2005 Developer Edition English Version Setup on Windows 7SQLServerDeveloperWindows
- Windows下安裝MongoDBWindowsMongoDB
- [Mysql] 2.Mysql 5.7 Install (Windows)MySqlWindows
- NPM INSTALL常見錯誤(windows篇)NPMWindows
- Powershell script to install Windows Updates (msu) from folderWindows
- Install Oracle Instant Client on Linux and WindowsOracleclientLinuxWindows
- oracle real cluster application install on windows with VMweaverOracleAPPWindows
- centos7 install idea and x-windowsCentOSIdeaWindows
- windows安裝mongodb詳細教程WindowsMongoDB
- SOFAStack Community | 歡迎加入ASTUnity
- 助力 .NET MAUI Community ToolkitUIUnity
- MYSQL版本:5.1.44-communityMySqlUnity
- step by step install oracle 10g rac asm on windowsOracle 10gASMWindows
- Windows 8 RP install VS2012Windows
- MongoDB Windows環境安裝及配置MongoDBWindows
- Mongodb在Windows下安裝及配置MongoDBWindows
- C# in Depth (Third Edition)C#
- 10 questions to DEK for iTuring communityUnity
- BGP團體屬性、CommunityUnity
- windows下pip install xx 遇到的 ConnectionResetError問題WindowsError
- Windows Server 2008完美安裝MySQL Community Server 5.7.16六步曲WindowsServerMySqlUnity
- windows 下 MongoDB 的安裝與啟動WindowsMongoDB
- windows下mongodb的安裝及啟動WindowsMongoDB
- Ext JS in Action, Second EditionJS
- Errata in Effective Java Second EditionJava
- 慶FastGithub加入.NET Core CommunityASTGithubUnity