Install MongoDB on Windows (Windows下安装MongoDB)

Install MongoDB on Windows

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 a hotfix to resolve an issue with memory mapped files on Windows.

Install MongoDB

1

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

2

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 does not work with 32-bit Windows.

3

Install the downloaded file.

In Windows Explorer, locate the downloaded MongoDB msi file, which typically is located in the defaultDownloads folder. Double-click the msi file. A set of screens will appear to guide you through the installation process.

4

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. D:\test\mongodb)

Run MongoDB

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.

1

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"

2

Start MongoDB.

To start MongoDB, run mongod.exe. For example, from the Command Prompt:

C:\Program Files\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:\Program Files\MongoDB\bin\mongod.exe from communicating on networks. All users should select Private Networks, such as my home or work network and click Allow access. For additional information on security and MongoDB, please see the Security Documentation.

3

Connect to MongoDB.

To connect to MongoDB through the mongo.exe shell, open another Command Prompt. When connecting, specify the data directory if necessary. This step provides several example connection commands.

If your MongoDB installation uses the default data directory, connect without specifying the data directory:

C:\mongodb\bin\mongo.exe

If you installation uses a different data directory, specify the directory when connecting, as in this 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"

If you want to develop applications using .NET, see the documentation of C# and MongoDB for more information.

4

Begin using MongoDB.

To begin using MongoDB, see Getting Started with MongoDB. Also consider the Production Notesdocument before deploying MongoDB in a production environment.

Configure a Windows Service for MongoDB

NOTE

There is a known issue for MongoDB 2.6.0, SERVER-13515, which prevents the use of the instructions in this section. For MongoDB 2.6.0, use Manually Create a Windows Service for MongoDB to create a Windows Service for MongoDB instead.

1

Configure directories and files.

Create a configuration file and a directory path for MongoDB log output (logpath):

Create a specific directory for MongoDB log files:

md "C:\Program Files\MongoDB\log"

In the Command Prompt, create a configuration file for the logpath option for MongoDB:

echo logpath="C:\Program Files\MongoDB\log\mongo.log" > "C:\Program Files\MongoDB\mongod.cfg"

2

Run the MongoDB service.

Run all of the following commands in Command Prompt with “Administrative Privileges:”

Install the MongoDB service. For --install to succeed, you must specify the logpath run-time option.

"C:\Program Files\MongoDB\bin\mongod.exe" --config "C:\Program Files\MongoDB\mongod.cfg" --install

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, mongod.exe will not start. The default value for dbpath is\data\db.

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.

3

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 MongoDB

The following procedure assumes you have installed MongoDB using the MSI installer, with the default pathC:\Program Files\MongoDB 2.6 Standard.

If you have installed in an alternative directory, you will need to adjust the paths as appropriate.

1

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.

2

Create directories.

Create directories for your database and log files:

mkdir c:\data\db
mkdir c:\data\log

3

Create a configuration file.

Create a configuration file. This file can include any of the configuration options for mongod, but mustinclude 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"

4

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 SUCCESS

5

Start the MongoDB service.

net start MongoDB

6

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
时间: 2024-08-04 18:42:16

Install MongoDB on Windows (Windows下安装MongoDB)的相关文章

Windows平台下安装MongoDB

MongoDB以其操作简单.完全免费.源码公开.随时下载等特点,被广泛应用于各种大型门户网站和专业网站,大大降低了运营成本.本文描述了在Widows平台下的安装步骤及其过程,供大家参考. 一.主要步骤 1.查看当前使用的Windows版本及架构 wmic os get caption wmic os get osarchitecture 2.下载对应的版本 http://www.mongodb.org/downloads 3.配置mongdb 创建存放数据文件的路径 md \data\db Yo

Windows 环境下安装MongoDB

mongoDB下载地址 https://www.mongodb.org/ 在mongoDB官网下载windows版本的mongoDB后解压出来(本文以解压到D盘为例) 在解压出来的MongoDB文件夹下创建data文件夹,然后在data文件夹下创建log和db两个文件夹 在log文件夹下创建一个空的mongodb.log文件 然后在mongodb文件夹下创建mongo.config文件 在mongo.config文件中加入下面两行内容 dbpath=D:\mongodb\data        

Windows 7下安装MongoDB

1.下载mongodb-win32-x86_64-2008plus-2.6.7-signed.msi(如今最新版本号已经到了3.0) 2.如果为64位操作系统则双击 mongodb-win32-x86_64-2008plus-2.6.7-signed.msi ,否则mongodb-win32-i386-2.6.7-signed.msi 点击Next 选择接受协议" I accept the terms in License Agreement"   dbDao.com.并点击Next

windows XAMPP下安装mongoDB

1.下载 下载地址:http://www.mongodb.org/downloads 2.安装 进入cmd第一步:D:\xampp\mongodb\bin\mongod.exe --dbpath=D:\xampp\mongodb\data\db 第二步安装到启动项里面去:D:\xampp\mongodb\bin\mongod.exe --dbpath=D:\xampp\mongodb\data\db --logpath=D:\xampp\mongodb\logs\MongoDB.log --in

Windows 10下 安装 MongoDB 的吐血经历

当安装一些软件时,往往会因为各种权限限制,导致安装失败或者出现Bug,比如这款MongoDB,我最终是用PowerShell安装,才成功没有出现Bug,不然就会有 service 'mongodb server' failed to start. verify that you have sufficient privileges to start system services 这样的问题!使用PowerSheel安装的过程如下,如果是在Win10,右击左下角的开始菜单,然后点击"Window

Windows 下安装 MongoDB

MongoDB 是目前在 IT 行业非常流行的一种非关系型数据库 (NoSql),其灵活的数据存储方式备受当前 IT 从业人员的青睐.这里主要讲如何在 Windows 平台下安装 MongoDB 下载 MongoDB 官网下载链接 如果被墙的话,请点击mongodb-win32-x86_64-2008plus-ssl-3.4.1-signed.msi 下载 手动简单的配置 配置环境变量 安装成功之后,将 mongodb 目录下的 bin 目录添加至 path 变量中,如: 创建数据库文件存放目录

在windows下安装MongoDB需要注意的地方

首先给出安装方法. 1.从http://www.mongodb.org 下载对应平台的安装包,这里是mongodb-win32-i386-2.2.1.zip 2.将压缩文件中的bin解压到安装目录下,这里是:d:\mongodb\bin 3.打开cmd命令行,进入目录d:\mongodb 4.创建日志目录:d:\mongodb\logs 5.创建数据文件目录:d:\mongodb\data 6.创建配置文件:d:\mongodb\mongod.cfg mongod.cfg的内容如下,第一行配置日

MongoDB学习总结(一) —— Windows平台下安装

一.基本概念 MongoDB是一个基于分布式文件存储的开源数据库系统,皆在为WEB应用提供可扩展的高性能数据存储解决方案.MongoDB将数据存储为一个文档,数据结构由键值key=>value组成.文档类似JSON对象.字段值可以包含其他文档,数组及文档数组. MongoDB数据库的几个基本概念: 1)一个 MongoDB 实例中,可以有零个或多个database(数据库). 2)数据库中可以有零个或多个 collections (集合).相当于传统关系数据库中table(表). 3)集合是由零

在32位Windows下安装Mongodb的过程:

在32位Windows下安装Mongodb的过程: 1.    下载Mongodb的zip文件 下载网站:https://fastdl.mongodb.org/win32/mongodb-win32-i386-2.6.9.zip 2.    将文件解压并放在D:\Mongodb(手动创建该目录) 3.    手动创建文件夹D:\Mongodb\data 4.    进入cmd,进入到D:\Mongodb\bin目录下 输入命令:mongod -dbpath "d:\Mongodb\data&qu

MongoDB笔记1:Windows下安装MongoDB

Windows下安装MongoDB非常简单.若是32位的操作系统,要安装32位的MongoDB:若是64位的系统,要安装64位的MongoDB. 这里以64位为例.具体步骤为: 一.下载MongoDB最新或较新版,这里下的是 mongodb-win32-x86_64-2008plus-ssl-3.2.0-signed.msi 二.安装 1 双击mongodb-win32-x86_64-2008plus-ssl-3.2.0-signed.msi,启动安装向导界面.选"Next"按纽 2