Install MongoDB Community Edition on Windows在Windows上安装MongoDB社区版
On this page本页内容
MongoDB Atlas
MongoDB Atlas is a hosted MongoDB service option in the cloud which requires no installation overhead and offers a free tier to get started.是云中托管的MongoDB服务选项,无需安装开销,并提供免费的入门层。
Overview概述
Use this tutorial to install MongoDB 7.0 Community Edition on Windows using the default installation wizard.使用本教程可以使用默认安装向导在Windows上安装MongoDB 7.0社区版。
MongoDB VersionMongoDB版本
This tutorial installs MongoDB 7.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.本教程安装MongoDB 7.0社区版。要安装不同版本的MongoDB Community,请使用此页面左上角的版本下拉菜单选择该版本的文档。
Installation Method安装方法
This tutorial installs MongoDB on Windows using the default MSI installation wizard. To install MongoDB using the 本教程使用默认的MSI安装向导在Windows上安装MongoDB。要使用msiexec.exe
command-line tool instead, see Install MongoDB using msiexec.exe. msiexec.exe
命令行工具安装MongoDB,请参阅使用msieexec.exe安装MongoDB。The msiexec.exe
tool is useful for system administrators who wish to deploy MongoDB in an unattended fashion using automation.msiexec.exe
工具对于希望使用自动化以无人值守的方式部署MongoDB的系统管理员非常有用。
Considerations注意事项
MongoDB Shell, mongosh
The MongoDB Shell (mongosh) is not installed with MongoDB Server. MongoDB Shell(mongosh
)未与MongoDB Server一起安装。You need to follow the mongosh installation instructions to download and install mongosh separately.您需要按照mongosh
安装说明分别下载和安装mongosh
。
Platform Support平台支持
MongoDB 7.0 Community Edition supports the following 64-bit versions of Windows on x86_64 architecture:MongoDB 7.0社区版支持以下64位版本的x86_64体系结构的Windows:
- Windows Server 2019
- Windows Server 2016
MongoDB only supports the 64-bit versions of these platforms.MongoDB只支持这些平台的64位版本。
See Platform Support for more information.有关更多信息,请参阅平台支持。
MongoDB is not supported on Windows Subsystem for Linux (WSL). To run MongoDB on Linux, use a supported Linux system.Windows Subsystem for Linux(WSL)不支持MongoDB。要在Linux上运行MongoDB,请使用受支持的Linux系统。
Virtualization虚拟化
Oracle offers experimental supportOracle在运行Hyper-V的Windows主机上提供了对VirtualBox的实验性支持 for VirtualBox on Windows hosts where Hyper-V is running.
。
However, Microsoft does not support VirtualBox on Hyper-V.但是,Microsoft不支持Hyper-V上的VirtualBox。
Disable Hyper-V if you want to install MongoDB on Windows using VirtualBox.如果要使用VirtualBox在Windows上安装MongoDB,请禁用Hyper-V。
Production Notes生产说明
Before deploying MongoDB in a production environment, consider the Production Notes document which offers performance considerations and configuration recommendations for production MongoDB deployments.在生产环境中部署MongoDB之前,请考虑产品说明文档,该文档为生产MongoDB部署提供了性能考虑和配置建议。
Full Time Diagnostic Data Capture全时诊断数据采集
MongoDB logs diagnostic data to assist with troubleshooting. MongoDB记录诊断数据,以帮助进行故障排除。For detailed information, see Full Time Diagnostic Data Capture.有关详细信息,请参阅实时诊断数据捕获。
On Windows, to collect system data such as disk, cpu, and memory, FTDC requires Microsoft access permissions from the following groups:在Windows上,要集合磁盘、cpu和内存等系统数据,FTDC需要以下组的Microsoft访问权限:
Performance Monitor Users性能监视器用户Performance Log Users性能日志用户
If the user running 如果运行mongod
and mongos
is not an administrator, add them to these groups to log FTDC data. mongod
和mongos
的用户不是管理员,请将它们添加到这些组中以记录FTDC数据。For more information, see the Microsoft documentation here有关详细信息,请参阅此处的Microsoft文档.
。
Install MongoDB Community Edition安装MongoDB社区版
Procedure过程
Follow these steps to install MongoDB Community Edition using the MongoDB Installer wizard. 按照以下步骤使用MongoDB安装程序向导安装MongoDB Community Edition。The installation process installs both the MongoDB binaries as well as the default configuration file 安装过程同时安装MongoDB二进制文件和默认配置文件<install directory>\bin\mongod.cfg
.<install directory>\bin\mongod.cfg
。
Download the installer.下载安装程序。
Download the MongoDB Community 从以下链接下载MongoDB Community .msi
installer from the following link:.msi
安装程序:
➤ MongoDB Download CenterMongoDB下载中心
In the Version dropdown, select the version of MongoDB to download.在“版本”下拉列表中,选择要下载的MongoDB版本。In the Platform dropdown, select Windows.在“平台”下拉列表中,选择“窗口”。In the Package dropdown, select msi.在“包”下拉列表中,选择“msi”。Click Download.单击“下载”。
Run the MongoDB installer.运行MongoDB安装程序。
For example, from the Windows Explorer/File Explorer:例如,从Windows资源管理器/文件资源管理器:
Go to the directory where you downloaded the MongoDB installer (转到下载MongoDB安装程序(.msi
file). By default, this is yourDownloads
directory..msi
文件)的目录。默认情况下,这是您的Downloads
目录。Double-click the双击.msi
file..msi
文件。
Follow the MongoDB Community Edition installation wizard.按照MongoDB Community Edition安装向导进行操作。
The wizard steps you through the installation of MongoDB and MongoDB Compass.向导将引导您完成MongoDB和MongoDB Compass的安装。
-
Choose Setup Type选择安装类型You can choose either the Complete (recommended for most users) or Custom setup type.您可以选择“完整”(建议大多数用户使用)或“自定义”设置类型。The Complete setup option installs MongoDB and the MongoDB tools to the default location. The Custom setup option allows you to specify which executables are installed and where.“完整”安装选项将MongoDB和MongoDB工具安装到默认位置。“自定义”设置选项允许您指定安装哪些可执行文件以及安装位置。
-
Service Configuration服务配置-
Starting in MongoDB 4.0, you can set up MongoDB as a Windows service during the install or just install the binaries.从MongoDB 4.0开始,您可以在安装过程中将MongoDB设置为Windows服务,也可以只安装二进制文件。The following installs and configures MongoDB as a Windows service.以下内容将MongoDB安装并配置为Windows服务。Starting in MongoDB 4.0, you can configure and start MongoDB as a Windows service during the install, and the MongoDB service is started upon successful installation.从MongoDB 4.0开始,您可以在安装过程中将MongoDB配置为Windows服务并启动,安装成功后即可启动MongoDB服务。-
Select Install MongoD as a Service MongoDB as a service.选择“将MongoDB作为服务安装”,从而让MongoDB成为服务。 -
Select either:选择其中一个:-
Run the service as Network Service user以网络服务用户身份运行服务(Default)违约This is a Windows user account that is built-in to Windows这是Windows内置的Windows用户帐户or
-
Run the service as a local or domain user以本地或域用户身份运行服务-
For an existing local user account, specify a period (i.e.对于现有的本地用户帐户,为“帐户域”指定一个句点(即.
) for the Account Domain and specify the Account Name and the Account Password for the user..
),并为用户指定“帐户名称”和“帐户密码”。 -
For an existing domain user, specify the Account Domain, the Account Name and the Account Password for that user.对于现有域用户,指定该用户的“帐户域”、“帐户名”和“帐户密码”。
-
-
-
Service Name服务名称. Specify the service name.。指定服务名称。Default name is默认名称为MongoDB
. If you already have a service with the specified name, you must choose another name.MongoDB
。如果您已经拥有具有指定名称的服务,则必须选择其他名称。 -
Data Directory数据目录. Specify the data directory, which corresponds to the。指定对应于--dbpath
.--dbpath
的数据目录。If the directory does not exist, the installer will create the directory and sets the directory access to the service user.如果该目录不存在,安装程序将创建该目录,并为服务用户设置目录访问权限。 -
Log Directory日志目录. Specify the Log directory, which corresponds to the。指定日志目录,该目录对应于--logpath
.--logpath
。If the directory does not exist, the installer will create the directory and sets the directory access to the service user.如果该目录不存在,安装程序将创建该目录,并为服务用户设置目录访问权限。
The following installs MongoDB only and does not configure MongoDB as a Windows service.以下仅安装MongoDB,不将MongoDB配置为Windows服务。If you choose not to configure MongoDB as a Windows service, uncheck the Install MongoD as a Service.如果您选择不将MongoDB配置为Windows服务,请取消选中“将Mongo安装为服务”。 -
-
Install MongoDB Compass安装MongoDB CompassOptional.可选择的To have the wizard install MongoDB Compass要让向导安装MongoDB Compass, select Install MongoDB Compass (Default).
,请选择“安装MongoDB Compass”(默认)。
When ready, click Install.准备好后,单击“安装”。
Install 安装mongosh
The .msi
installer does not include mongosh. .msi
安装程序不包括mongosh
。Follow the mongosh installation instructions to download and install the shell separately.按照mongosh
安装说明分别下载和安装外壳。
If You Installed MongoDB as a Windows Service如果您将MongoDB作为Windows服务安装
The MongoDB service starts upon successful installation.MongoDB服务在成功安装后启动。
If you would like to customize the service, you must stop the service. 如果要自定义该服务,则必须停止该服务。Customize the MongoDB instance by editing the configuration file at 通过编辑<install directory>\bin\mongod.cfg
.<install directory>\bin\mongod.cfg
的配置文件来自定义MongoDB实例。
For information about the available configuration options, refer to Configuration File Options.有关可用配置选项的信息,请参阅配置文件选项。
After making changes, start the service again.更改后,请重新启动服务。
If You Did Not Install MongoDB as a Windows Service如果您没有将MongoDB作为Windows服务安装
If you only installed the executables and did not install MongoDB as a Windows service, you must manually start the MongoDB instance.如果您只安装了可执行文件,而没有将MongoDB作为Windows服务安装,则必须手动启动MongoDB实例。
See Run MongoDB Community Edition from the Command Interpreter for instructions to start a MongoDB instance.有关启动MongoDB实例的说明,请参阅从命令解释器运行MongoDB社区版。
Run MongoDB Community Edition as a Windows Service将MongoDB Community Edition作为Windows服务运行
Starting in version 4.0, you can install and configure MongoDB as a Windows Service during installation. 从4.0版本开始,您可以在安装过程中将MongoDB作为“Windows服务”进行安装和配置。The MongoDB service starts upon successful installation. MongoDB服务在成功安装后启动。Configure the MongoDB instance with the configuration file 使用配置文件<install directory>\bin\mongod.cfg
.<install directory>\bin\mongod.cfg
配置MongoDB实例。
If you have not already done so, follow the mongosh installation instructions to download and install the MongoDB Shell (mongosh).如果您还没有这样做,请按照mongosh
安装说明下载并安装MongoDB Shell(mongosh)。
Be sure to add the path to your 请确保在安装过程中将mongosh.exe
binary to your PATH
environment variable during installation.mongosh.exe
二进制文件的路径添加到PATH
环境变量中。
Open a new Command Interpreter and enter 打开一个新的“命令解释器”,输入mongosh.exe
to connect to MongoDB.mongosh.exe
连接到MongoDB。
For more information on connecting to a 有关使用mongod
using mongosh.exe, such as connecting to a MongoDB instance running on a different host and/or port, see Connect to a Deployment.mongosh.exe
连接到mongod
的更多信息,例如连接到运行在不同主机和/或端口上的MongoDB实例,请参阅连接到部署。
For information on CRUD (Create, Read, Update, Delete) operations, see:有关CRUD(创建、读取、更新、删除)操作的信息,请参阅:
Start MongoDB Community Edition as a Windows Service将MongoDB Community Edition作为Windows服务启动
To start/restart the MongoDB service, use the Services console:要启动/重新启动MongoDB服务,请使用服务控制台:
From the Services console, locate the MongoDB service.在服务控制台中,找到MongoDB服务。Right-click on the MongoDB service and click Start.右键单击MongoDB服务,然后单击“开始”。
Stop MongoDB Community Edition as a Windows Service停止将MongoDB Community Edition作为Windows服务
To stop/pause the MongoDB service, use the Services console:要停止/暂停MongoDB服务,请使用服务控制台:
From the Services console, locate the MongoDB service.在服务控制台中,找到MongoDB服务。- Right-click on the MongoDB service and click Stop (or Pause).
Remove MongoDB Community Edition as a Windows Service将MongoDB Community Edition作为Windows服务删除
To remove the MongoDB service, first use the Services console to stop the service. 要删除MongoDB服务,首先使用服务控制台停止该服务。Then open a Windows command prompt/interpreter (
cmd.exe
) as an Administrator, and run the following command:
sc.exe delete MongoDB
Run MongoDB Community Edition from the Command Interpreter从命令解释器运行MongoDB Community Edition
You can run MongoDB Community Edition from the Windows command prompt/interpreter (cmd.exe
) instead of as a service.
Open a Windows command prompt/interpreter (
cmd.exe
) as an Administrator.
You must open the command interpreter as an Administrator.您必须以“管理员”身份打开命令解释器。
Create database directory.创建数据库目录。
Create the data directory where MongoDB stores data. MongoDB's default data directory path is the absolute path \data\db
on the drive from which you start MongoDB.
From the Command Interpreter, create the data directories:从“命令解释器”创建数据目录:
cd C:\
md "\data\db"
Start your MongoDB database.启动MongoDB数据库。
To start MongoDB, run 要启动MongoDB,请运行mongod.exe
.mongod.exe
。
"C:\Program Files\MongoDB\Server\7.0\bin\mongod.exe" --dbpath="c:\data\db"
The --dbpath
option points to your database directory.--dbpath
选项指向数据库目录。
If the MongoDB database server is running correctly, the Command Interpreter displays:如果MongoDB数据库服务器运行正常,“命令解释器”将显示:
[initandlisten] waiting for connections
Depending on the Windows Defender Firewall settings on your Windows host, Windows may display a Security Alert dialog box about blocking "some features" of
C:\Program Files\MongoDB\Server\7.0\bin\mongod.exe
from communicating on networks. To remedy this issue:要解决此问题:
Click Private Networks, such as my home or work network.单击“专用网络,例如我的家庭或工作网络”。Click Allow access.单击“允许访问”。
To learn more about security and MongoDB, see the Security Documentation.要了解有关安全性和MongoDB的更多信息,请参阅安全文档。
Connect to MongoDB.连接到MongoDB。
If you have not already done so, follow the mongosh installation instructions to download and install the MongoDB Shell (mongosh).如果您还没有这样做,请按照mongosh
安装说明下载并安装MongoDB Shell(mongosh
)。
Be sure to add the path to your mongosh.exe
binary to your PATH
environment variable during installation.
Open a new Command Interpreter and enter mongosh.exe
to connect to MongoDB.
For more information on connecting to mongod
using mongosh.exe, such as connecting to a MongoDB instance running on a different host and/or port, see Connect to a Deployment.
For information on CRUD (Create, Read, Update, Delete) operations, see:有关CRUD(创建、读取、更新、删除)操作的信息,请参阅:
Additional Considerations其他注意事项
Localhost Binding by Default默认情况下的Localhost绑定
By default, MongoDB launches with bindIp
set to 127.0.0.1
, which binds to the localhost network interface. This means that the mongod.exe
can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod.exe
, and the mongod.exe
will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:此值可以配置为:
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. 在将实例绑定到可公开访问的IP地址之前,必须保护群集不受未经授权的访问。For a complete list of security recommendations, see Security Checklist. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp
, see IP Binding.
Point Releases and .msi
点发布和.msi
.msi
If you installed MongoDB with the Windows installer (.msi
), the .msi
automatically upgrades within its release series (e.g. 4.2.1 to 4.2.2).
Upgrading a full release series (e.g. 4.0 to 4.2) requires a new installation.
Add MongoDB binaries to the System PATH将MongoDB二进制文件添加到系统PATH
If you add C:\Program Files\MongoDB\Server\7.0\bin
to your System PATH
you can omit the full path to the MongoDB Server binaries. You should also add the path to mongosh if you have not already done so.