如何在 Windows 上安装 mongoDB?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2404742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install mongoDB on windows?
提问by Industrial
I am trying to test out mongoDB and see if it is anything for me. I downloaded the 32bit windows version, but have no idea on how to continue from now on.
我正在尝试测试 mongoDB,看看它是否适合我。我下载了 32 位 windows 版本,但不知道从现在开始如何继续。
I normally use the WAMP services for developing on my local computer. Can i run mongoDB on Wamp?
我通常使用 WAMP 服务在本地计算机上进行开发。我可以在 Wamp 上运行 mongoDB 吗?
However, what's the best (easiest!) way to make it work on windows?
但是,使它在 Windows 上运行的最佳(最简单!)方法是什么?
Thanks!
谢谢!
采纳答案by shingara
It's not like WAMP. You need to start mongoDB database with a command after directory has been created C:/database_mongo
它不像 WAMP。创建目录后,您需要使用命令启动 mongoDB 数据库 C:/database_mongo
mongod --dbpath=C:/database_mongo/
mongod --dbpath=C:/database_mongo/
you can then connect to mongodb using commands.
然后,您可以使用命令连接到 mongodb。
回答by Shivam Srivastava
Mongo Installation Process in Windows
Windows 中的 Mongo 安装过程
Are you ready for the installation … and use … Technically, it's not an installation it's just Downloading…
您准备好安装了吗……并使用……从技术上讲,这不是安装,只是下载……
I. Downloadthe zip file http://www.mongodb.org/downloads
一、 下载zip文件http://www.mongodb.org/downloads
II. Extractit and copy the files into your desired location.
二、 提取它并将文件复制到您想要的位置。
III. Startthe DB engine.
三、启动数据库引擎。
IV. Testthe installation and use it.
四、 测试安装并使用它。
That's it! So simple, right? Ok let's start
就是这样!这么简单,对吧?好的,让我们开始
1. Download the zip file
1.下载压缩文件
- Go to http://www.mongodb.org/downloads
You will see a screen like this:
- I am using a windows 7 32 bit machine - that's why I downloaded the package marked in red.
Click download (It only takes a few seconds).
- Wow... I got that downloaded. It was a zipped file called
mongodb-win32-i386-2.4.4.zip
(The name of the folder will change according to the version you download, here I got version 2.4.4).
- Wow... I got that downloaded. It was a zipped file called
- 转到http://www.mongodb.org/downloads
你会看到一个这样的屏幕:
- 我使用的是 Windows 7 32 位机器 - 这就是我下载标记为红色的包的原因。
单击下载(只需几秒钟)。
- 哇...我下载了。这是一个名为的压缩文件
mongodb-win32-i386-2.4.4.zip
(文件夹的名称会根据您下载的版本而改变,我这里是 2.4.4 版)。
- 哇...我下载了。这是一个名为的压缩文件
OK all set.
OK,一切就绪。
2. Extract
2. 提取
- Extract the zip
- Copy the files into a desired location in your machine.
- I am going to copy the extracted files to my D drive, since I don't have many files there.
- Alright then where are you planning to paste the mongo files? In C: or in your Desktop itself?
- Ok, no matter where you paste... In the snap shot below, you can see that I have navigated to the bin folder inside the Mongo folder. I count fifteen files inside bin. What about you?
- 解压缩
- 将文件复制到机器中的所需位置。
- 我打算将提取的文件复制到我的 D 盘,因为那里没有很多文件。
- 好吧,那么您打算将 mongo 文件粘贴到哪里?在 C: 中还是在您的桌面中?
- 好的,无论您粘贴到何处...在下面的快照中,您可以看到我已导航到 Mongo 文件夹内的 bin 文件夹。我在 bin 内数了 15 个文件。那你呢?
Finished! That's all
完成的!就这样
What we have to do next?
我们接下来要做什么?
3. Start the DB engine
3. 启动数据库引擎
Let's go and start using our mongo db...
让我们开始使用我们的 mongo 数据库...
- Open up a command prompt, then navigate to `bin` in the mongo folder ![Navigating to mongo's bin folder][4]
- Type `mongo.exe` (which is the command used to start mongo Db Power shell). Then see the below response.. ![Executing mongo.exe][5] *That was an awesome exception J LOL … What is that?* > Couldn't connect to server. *Why did the exception happen? I have no idea... Did I create a server in between?* *No.* *Right, then how come it connected to a server in between? Silly Machine …Jz.* *I got it! Like all other DBs - we have to start the DB engine before we use it.* *So, how can we start it?*
- We have to start the mongo db by using the command `mongod`. Execute this from the `bin` folder of mongo. *Let's see what had happened.* ![enter image description here][6] *Again a wonderfully formatted exception J we got right? Did you notice what I have highlighted on top? Yeah it is the mongod command. The second one is the exception asking us to create a folder called data. And, inside the data folder, a folder called `db`.* *So we have to create these `data\db` folders.* *The next question is where to create these folders?*
- We have to create the `data\db` folders in the `C` drive of our BOX in which we are installing mongo. Let's go and create the folder structure in C drive.
A question arises here: "Is it mandatory to create the data\db directories inside C?" Nooo, not really. Mongo looks in `C` by default for this folder, but you can create them wherever you want. However, if it's not in `C`, you have to tell mongo where it is.
*In other words, if you don't want the mongo databases to be on `C:\`, you have to set the db path for mongo.exe.*
Optional
- Ok, I will create those folders in some other location besides `C` for better understanding of this option. I will create then in the `D` drive root, with the help of cmd. Why? Because it's an opportunity for us to remember the old dos commands... ![enter image description here][7]
- The next step is to set the Db path to mongo.exe. Navigate back to `bin`, and enter the command, `mongod.exe --dbpath d:\data`. I got the response below: ![enter image description here][8] I Hope everything went well... Because I didn't see any ERROR *** in the console J.
- Next, we can go and start the db using the command `start mongo.exe`![enter image description here][9] I didn't see any error or warning messages. But, we have to supply a command to make sure mongo is up and running, i.e. mongod will get a response: ![enter image description here][10] Hope everything went well.
- 打开命令提示符,然后导航到 mongo 文件夹中的 `bin`![导航到 mongo 的 bin 文件夹][4]
- 输入`mongo.exe`(这是用于启动mongo Db Power shell的命令)。然后看到下面的响应.. ![Executing mongo.exe][5] *这是一个很棒的例外 J LOL ... 那是什么?* > 无法连接到服务器。*为什么会发生异常?我不知道...我在两者之间创建了一个服务器吗?* *没有。* *对,那么它是如何连接到中间的服务器的?傻机器……Jz。* *我明白了!像所有其他数据库一样 - 我们必须在使用它之前启动数据库引擎。* *那么,我们如何启动它?*
- 我们必须使用命令 `mongod` 来启动 mongo db。从 mongo 的 `bin` 文件夹中执行此操作。*让我们看看发生了什么。* ![在此处输入图像描述][6] *又是一个奇妙的格式化异常 J 我们猜对了吗?你注意到我在上面突出显示的内容了吗?是的,这是 mongod 命令。第二个是异常要求我们创建一个名为 data 的文件夹。并且,在data文件夹中,有一个名为`db`的文件夹。* *所以我们必须创建这些`data\db`文件夹。* *下一个问题是在哪里创建这些文件夹?*
- 我们必须在安装 mongo 的 BOX 的 C 驱动器中创建 data\db 文件夹。让我们去创建C盘的文件夹结构。这里出现了一个问题:“是否必须在 C 中创建 data\db 目录?” 不,不是真的。Mongo 默认在`C` 中查找这个文件夹,但你可以在任何你想要的地方创建它们。但是,如果它不在 `C` 中,你必须告诉 mongo 它在哪里。*换句话说,如果您不希望 mongo 数据库位于 `C:\` 上,则必须为 mongo.exe 设置 db 路径。*
可选的
- 好的,为了更好地理解此选项,我将在除 `C` 之外的其他位置创建这些文件夹。然后我将在 cmd 的帮助下在 `D` 驱动器根目录中创建。为什么?因为这是一个让我们记住旧的 dos 命令的机会......![在此处输入图像描述][7]
- 下一步是将 Db 路径设置为 mongo.exe。导航回`bin`,然后输入命令`mongod.exe --dbpath d:\data`。我得到以下回复:![在此处输入图片描述][8] 我希望一切顺利...因为我在控制台 J 中没有看到任何 ERROR ***。
- 接下来,我们可以使用命令`start mongo.exe`来启动数据库![在此处输入图像描述][9]我没有看到任何错误或警告消息。但是,我们必须提供一个命令来确保 mongo 启动并运行,即 mongod 将得到响应: ![在此处输入图像描述][10] 希望一切顺利。
4. Test the Mongo DB installation
4.测试Mongo DB安装
Now we have to see our DB right? Yea very much, Otherwise how will we know it's running?
现在我们必须看到我们的数据库对吗?非常好,否则我们怎么知道它正在运行?
For testing purpose MONGO has got a DB called test
by default. Lets go query that.
出于测试目的, MONGO 有一个test
默认调用的数据库。让我们去查询。
But how without any management studios? Unlike SQL, we have to depend on the command prompt. Yes exactly the same command prompt… our good old command prompt… Heiiiii.. Don't get afraid yes it's our old command prompt only. Ok let's go and see how we are going to use it…
但是没有任何管理工作室怎么办?与 SQL 不同,我们必须依赖命令提示符。是的,完全相同的命令提示符......我们的旧命令提示符...... Heiiii.. 不要害怕,是的,它只是我们的旧命令提示符。好的,让我们去看看我们将如何使用它......
Ohhh Nooo… don't closethe above Command prompt, leave it as it is…
Ohhh Nooo...不要关闭上面的命令提示符,保持原样...
I am sure you people may be remembering the old C programming which we have done on our college day's right?
我相信你们可能还记得我们在大学时代做过的旧 C 编程吧?
mongo
or mongo.exe
again and see what happens.You will get a screen as shown below:
mongo
或mongo.exe
再次查看会发生什么。您将看到如下所示的屏幕:
test
, try inserting a record into it.The next question here is "How will we insert?" Does mongo have SQL commands? No, mongo has got only commands to help with.
The basic command to insertis
db.test.save( { KodothTestField: ‘My name is Kodoth' } )
Where test
is the DB and .save
is the insert command. KodothTestField
is the column or field name, and My name is Kodoth
is the value.
test
,尝试在其中插入一条记录。下一个问题是“我们将如何插入?” mongo 有 SQL 命令吗?不,mongo 只有命令可以帮助。
插入的基本命令是
db.test.save( { KodothTestField: 'My name is Kodoth' } )
哪里test
是数据库,.save
是插入命令。KodothTestField
是列名或字段名,My name is Kodoth
是值。
db.test.find()
Our Data got successfully inserted … Hurrayyyyyy..
I know that you are thinking about the number which is displayed with every record right called ObjectId. It's like a unique id field in SQL that auto-increments and all. Have a closer look you can see that the Object Id ends with 92, so it's different for each and every record.
At last we are successful in installing and verifying the MONGO right. Let's have a party... So do you agree now MONGO is as Sweet as MANGO?
db.test.find()
我们的数据已成功插入...... Hurrayyyyyy..
我知道您正在考虑与每个名为 ObjectId 的记录权限一起显示的数字。它就像 SQL 中的一个唯一 id 字段,它会自动递增等等。仔细观察,您会发现 Object Id 以 92 结尾,因此每条记录都不同。
最后我们成功安装并验证了 MONGO 权限。让我们开个派对吧……所以你现在同意 MONGO 和 MANGO 一样甜蜜吗?
Also we have 3rd party tools to explore the MONGO. One is called MONGO VUE. Using this tool we can perform operations against the mongo DB like we use Management studio for SQL Server.
我们还有 3rd 方工具来探索 MONGO。一种叫做 MONGO VUE。使用这个工具,我们可以像使用 SQL Server 的 Management Studio 一样对 mongo DB 执行操作。
Can you just imagine an SQL server or Oracle Db with entirely different rows in same table? Is it possible in our relational DB table? This is how mongo works. I will show you how we can do that…
您能想象一个 SQL 服务器或 Oracle Db 在同一个表中具有完全不同的行吗?在我们的关系数据库表中可能吗?这就是 mongo 的工作方式。我将向您展示我们如何做到这一点......
First I will show you how the data will look in a relational DB.
首先,我将向您展示数据在关系数据库中的外观。
For example consider an Employee table and a Student table in relational way. The schemas would be entirely different right? Yes exactly…
例如,以关系方式考虑 Employee 表和 Student 表。模式会完全不同,对吗?对,就是这样…
Let us now see how it will look in Mongo DB. The above two tables are combined into single Collection in Mongo…
现在让我们看看它在 Mongo DB 中的样子。以上两个表在 Mongo 中合并为一个 Collection…
This is how Collections are stored in Mongo. I think now you can feel the difference really right? Every thing came under a single umbrella. This is not the right way but I just wanted to show you all how this happens that's why I combined 2 entirely different tables in to one single Collection.
这就是集合在 Mongo 中的存储方式。我想现在你真的能感觉到差异了吧?每件事都在一把伞下。这不是正确的方法,但我只是想向大家展示这是如何发生的,这就是为什么我将 2 个完全不同的表合并到一个集合中。
If you want to try out you can use below test scripts
如果你想尝试,你可以使用下面的测试脚本
***********************
TEST INSERT SCRIPT
*********EMPLOYEE******
db.test.save( { EmployeId: "1", EmployeFirstName: "Kodoth", EmployeLastName:"KodothLast", EmployeAge:"14" } )
db.test.save( { EmployeId: "2", EmployeFirstName: "Kodoth 2", EmployeLastName:"Kodoth Last2", EmployeAge:"14" } )
db.test.save( { EmployeId: "3", EmployeFirstName: "Kodoth 3", EmployeLastName:"Kodoth Last3", EmployeAge:"14" } )
******STUDENT******
db.test.save( { StudentId: "1", StudentName: "StudentName", StudentMark:"25" } )
db.test.save( { StudentId: "2", StudentName: "StudentName 2", StudentMark:"26" } )
db.test.save( {StudentId: "3", StudentName: "StudentName 3", StudentMark:"27"} )
************************
Thanks
谢谢
回答by John Channing
Pretty good documentation is provided on the MongoDB website
MongoDB 网站上提供了相当不错的文档
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 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.
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.
D:\test\mongodb
)Run MongoDB
Warning:
Do not make
mongod.exe
visible on public networks without running in “Secure Mode” with the auth setting. 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 tomongod.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"
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.
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.
Begin using MongoDB.
To begin using MongoDB, see Getting Started with MongoDB. Also consider the Production Notes document before deploying MongoDB in a production environment.
Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.
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.
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"
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:\Program Files\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.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 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 configuration file. This file can include any of the configuration options for mongod, 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 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
安装 MongoDB
确定您需要哪个 MongoDB 构建。
适用于 Windows 的 MongoDB 共有三个版本:
MongoDB for Windows Server 2008 R2 版本(即 2008R2)仅在 Windows Server 2008 R2、Windows 7 64 位和更新版本的 Windows 上运行。此版本利用了 Windows 平台的最新增强功能,无法在旧版本的 Windows 上运行。
适用于 Windows 64 位的 MongoDB 在比 Windows XP 更新的任何 64 位版本的 Windows 上运行,包括 Windows Server 2008 R2 和 Windows 7 64 位。
适用于 Windows 32 位的 MongoDB 可在比 Windows XP 更新的任何 32 位 Windows 版本上运行。32 位版本的 MongoDB 仅适用于较旧的系统以及用于测试和开发系统。32 位版本的 MongoDB 仅支持小于 2GB 的数据库。
要查找您正在运行的 Windows 版本,请在命令提示符中输入以下命令:
wmic os get osarchitecture
下载适用于 Windows 的 MongoDB。
从 MongoDB 下载页面下载 MongoDB 的最新生产版本。确保为您的 Windows 系统下载正确版本的 MongoDB。64 位版本的 MongoDB 不适用于 32 位 Windows。
安装下载的文件。
在 Windows 资源管理器中,找到下载的 MongoDB msi 文件,该文件通常位于默认的下载文件夹中。双击 msi 文件。将出现一组屏幕,指导您完成安装过程。
将 MongoDB 文件夹移动到另一个位置(可选)。
要移动 MongoDB 文件夹,您必须以管理员身份发出移动命令。例如,要将文件夹移动到 C:\mongodb:
选择Start Menu> All Programs> Accessories。
右键单击命令提示符并从弹出菜单中选择以管理员身份运行。
发出以下命令:
cd \ move C:\mongodb-win32-* C:\mongodb
MongoDB 是自包含的,没有任何其他系统依赖项。您可以从您选择的任何文件夹运行 MongoDB。您可以在任何文件夹中安装 MongoDB(例如
D:\test\mongodb
)运行 MongoDB
警告:
如果不
mongod.exe
使用 auth 设置在“安全模式”下运行,请不要在公共网络上可见。MongoDB 旨在运行在受信任的环境中,数据库默认不启用“安全模式”。
设置 MongoDB 环境。
MongoDB 需要一个数据目录来存储所有数据。MongoDB 的默认数据目录路径是\data\db。在命令提示符下使用以下命令创建此文件夹:
md \data\db
您可以使用
--dbpath
选项指定数据文件的备用路径mongod.exe
,例如:C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data
如果您的路径包含空格,请将整个路径用双引号括起来,例如:
C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"
启动 MongoDB。
要启动 MongoDB,请运行
mongod.exe
. 例如,从命令提示符:C:\Program Files\MongoDB\bin\mongod.exe
这将启动主 MongoDB 数据库进程。控制台输出中的等待连接消息表明 mongod.exe 进程运行成功。
根据您系统的安全级别,Windows 可能会弹出一个安全警报对话框,内容是阻止 C:\Program Files\MongoDB\bin\mongod.exe 的“某些功能”在网络上进行通信。所有用户都应选择专用网络,例如我的家庭或工作网络,然后单击允许访问。有关安全性和 MongoDB 的其他信息,请参阅安全文档。
连接到 MongoDB。
要通过 mongo.exe shell 连接到 MongoDB,请打开另一个命令提示符。连接时,根据需要指定数据目录。此步骤提供了几个示例连接命令。
如果您的 MongoDB 安装使用默认数据目录,请在不指定数据目录的情况下进行连接:
C:\mongodb\bin\mongo.exe
如果安装使用不同的数据目录,请在连接时指定目录,如下例所示:
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data
如果您的路径包含空格,请将整个路径用双引号括起来。例如:
C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"
如果您想使用 .NET 开发应用程序,请参阅 C# 和 MongoDB 的文档以获取更多信息。
开始使用 MongoDB。
要开始使用 MongoDB,请参阅 MongoDB 入门。在生产环境中部署 MongoDB 之前,还要考虑生产注释文档。
稍后,要停止 MongoDB,请在运行 mongod 实例的终端中按 Control+C。
为 MongoDB 配置 Windows 服务
笔记:
MongoDB 2.6.0 存在一个已知问题 SERVER-13515,它阻止使用本节中的说明。对于 MongoDB 2.6.0,请改用手动为 MongoDB 创建 Windows 服务来为 MongoDB 创建 Windows 服务。
配置目录和文件。
为 MongoDB 日志输出创建配置文件和目录路径(logpath):
为 MongoDB 日志文件创建特定目录:
md "C:\Program Files\MongoDB\log"
在命令提示符中,为 MongoDB 的 logpath 选项创建一个配置文件:
echo logpath=C:\Program Files\MongoDB\log\mongo.log > "C:\Program Files\MongoDB\mongod.cfg"
运行 MongoDB 服务。
使用“管理权限”在命令提示符中运行以下所有命令:
安装 MongoDB 服务。为了
--install
取得成功,你必须指定日志路径运行时的选项。"C:\Program Files\MongoDB\bin\mongod.exe" --config "C:\Program Files\MongoDB\mongod.cfg" --install
根据需要修改 mongod.cfg 文件的路径。
要使用备用 dbpath,请在配置文件(例如 C:\Program Files\MongoDB\mongod.cfg)中或在命令行中使用 --dbpath 选项指定路径。
如果 dbpath 目录不存在,mongod.exe 将不会启动。dbpath 的默认值为
\data\db
.如果需要,您可以为 mongod.exe 或 mongos.exe 的多个实例安装服务。安装了一个独特的每个服务
--serviceName
和--serviceDisplayName
。仅当存在足够的系统资源且您的系统设计需要时才使用多个实例。根据需要停止或删除 MongoDB 服务。
要停止 MongoDB 服务,请使用以下命令:
net stop MongoDB
要删除 MongoDB 服务,请使用以下命令:
"C:\Program Files\MongoDB\bin\mongod.exe" --remove
手动为 MongoDB 创建 Windows 服务
以下过程假设您已使用 MSI 安装程序安装了 MongoDB,默认路径为 C:\Program Files\MongoDB 2.6 Standard。
如果已安装在备用目录中,则需要适当调整路径。
打开管理员命令提示符。
Windows 7 / Vista / Server 2008(和 R2)
按Win+ R,然后键入
cmd
,然后按Ctrl+ Shift+ Enter。视窗 8
按Win+ X,然后按A。
从管理员命令提示符执行其余步骤。
创建目录。
为您的数据库和日志文件创建目录:
mkdir c:\data\db mkdir c:\data\log
创建配置文件。
创建配置文件。此文件可以包含 mongod 的任何配置选项,但必须包含 logpath 的有效设置:
下面创建一个配置文件,在配置文件中指定 logpath 和 dbpath 设置:
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"
创建 MongoDB 服务。
创建 MongoDB 服务。
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
在“=
”和配置值(例如“binPath=
”)之间需要一个空格,并需要一个“”来转义双引号。如果创建成功,将显示以下日志消息:
[SC] CreateService SUCCESS
启动 MongoDB 服务。
net start MongoDB
根据需要停止或删除 MongoDB 服务。
要停止 MongoDB 服务,请使用以下命令:
net stop MongoDB
要删除 MongoDB 服务,请先停止该服务,然后运行以下命令:
sc.exe delete MongoDB
回答by JCutrer
I realize you've already accepted an answer for this, but I wrote this short howto article to install mongodb into the c:\wamp
directory and run it as a service. Here is the gist of it.
我意识到您已经接受了这个答案,但我写了这篇简短的 howto 文章来将 mongodb 安装到c:\wamp
目录中并将其作为服务运行。这是它的要点。
Create these directories
创建这些目录
mkdir c:\wamp\bin\mongodb\mongodb-win32...2.x.x\data
mkdir c:\wamp\bin\mongodb\mongodb-win32...2.x.x\data\db
mkdir c:\wamp\bin\mongodb\mongodb-win32...2.x.x\logs
mkdir c:\wamp\bin\mongodb\mongodb-win32...2.x.x\conf
Download and extract win32 binaries into c:\wamp directory along side mysql, apache.
将 win32 二进制文件下载并解压到 mysql、apache 旁边的 c:\wamp 目录中。
Create a mongo.conf file
创建一个 mongo.conf 文件
c:\wamp\bin\mongodb\mongodb-win32…2.x.x\conf\mongodb.conf
# mongodb.conf
# data lives here
dbpath=C:\wamp\bin\mongodb\mongodb-win32...2.x.x\data\db
# where to log
logpath=C:\wamp\bin\mongodb\mongodb-win32...2.x.x\logs\mongodb.log
logappend=true
# only run on localhost for development
bind_ip = 127.0.0.1
port = 27017
rest = true
Install as a service
作为服务安装
mongod.exe --install --config c:\wamp\bin\mongodb\mongodb-win32...2.x.x\conf\mongodb.conf --logpath c:\wamp\bin\mongodb\mongodb-win32...2.x.x\logs\mongodb.log
Set service to automatic and start it using services.msc
将服务设置为自动并使用 services.msc 启动它
Add path to mongo.exe to your path
将 mongo.exe 的路径添加到您的路径中
Need more details? Read the full article here...
需要更多细节?在此处阅读全文...
回答by Muhammad Zeshan Ghafoor
Step by Step Solution for windows 32 bit
Windows 32 位的分步解决方案
- Download msi file for windows 32 bit.
- Double click Install it, choose custom and browse the location where ever you have to install(personally i have create the mongodb folder in E drive and install it there).
- Ok,now you have to create the data\db two folder where ever create it, i've created it in installed location root e.g on E:\
- Now link the mongod to these folder for storing data use this
command or modify according to your requirement go to using cmd
E:\mongodb\bin
and after that write in consolemongod --dbpath E:\data
it will link. - Now navigate to E:\mongodb\bin and write mongod using cmd.
- Open another cmd by right click and run as admin point to your monogodb installed directory and then to bin just like E:\mongodb\bin and write this mongo.exe
- Next - write
db.test.save({Field:'Hello mongodb'})
this command will insert the a field having name Fieldand its value Hello mongodb. - Next, check the record
db.test.find()
and press enter you will find the record that you have recently entered.
- 下载适用于 Windows 32 位的 msi 文件。
- 双击安装它,选择自定义并浏览您必须安装的位置(我个人已经在 E 驱动器中创建了 mongodb 文件夹并将其安装在那里)。
- 好的,现在您必须在创建它的地方创建 data\db 两个文件夹,我已经在安装位置根目录中创建了它,例如在 E:\
- 现在将 mongod 链接到这些用于存储数据的文件夹,使用此命令或根据您的要求进行修改,转到使用 cmd
E:\mongodb\bin
,然后在控制台中写入mongod --dbpath E:\data
它将链接。 - 现在导航到 E:\mongodb\bin 并使用 cmd 编写 mongod。
- 通过右键单击打开另一个 cmd 并以管理员身份运行到您的 monogodb 安装目录,然后像 E:\mongodb\bin 一样进入 bin 并编写这个 mongo.exe
- 接下来 - 编写
db.test.save({Field:'Hello mongodb'})
此命令将插入具有名称Field及其值Hello mongodb 的字段。 - 接下来,检查记录
db.test.find()
并按回车键,您将找到您最近输入的记录。
回答by Harit Singh
Its very simple to install Mongo DB on windows 7 ( i used 32 bit win7 OS)
在 Windows 7 上安装 Mongo DB 非常简单(我使用的是 32 位 win7 操作系统)
- Install the correct version of Mongodb ( according to ur bit 32/64 .. imp :- 64 bit is not compatible with 32 bit and vice versa)
- 安装正确版本的 Mongodb(根据您的位 32/64 .. imp :- 64 位与 32 位不兼容,反之亦然)
2.u can install Mongodb from thius website ( acc to ur OS) http://www.mongodb.org/downloads?_ga=1.79549524.1754732149.1410784175
2.您可以从thius网站(根据您的操作系统)安装Mongodb http://www.mongodb.org/downloads?_ga=1.79549524.1754732149.1410784175
- DOWNLOAD THE .MSI OR zip file .. and install with proper privellages
- 下载 .MSI 或 zip 文件 .. 并使用适当的权限安装
4.copy the mongodb folder from c:programfiles to d: [optional]
4.将mongodb文件夹从c:programfiles复制到d:[可选]
5.After installation open command prompt ( as administrator .. right click on cmd and u will find the option)
5.安装后打开命令提示符(以管理员身份..右键单击cmd,您将找到该选项)
navigate to D:\MongoDB 2.6 Standard\bin
run mongo.exe ... you might get this error
If you get then no isse you just need to do following steps
导航到 D:\MongoDB 2.6 Standard\bin
运行 mongo.exe ... 你可能会收到这个错误
如果你得到那么没有问题,你只需要执行以下步骤
i) try the coomand in following image yo will get to know the error
i) 尝试下图中的 coomand 你会知道错误
ii)This means that u neeed to create a directory \data\db
ii)这意味着你需要创建一个目录\data\db
iii) now you have two options either create above directory in c drive or create any "xyz" name directory somewhere else ( doesnot make and diffrence) .. lets create a directory of mongodata in d:
iii) 现在您有两个选项,要么在 c 驱动器中创建上面的目录,要么在其他地方创建任何“xyz”名称目录(不制作和差异)..让我们在 d 中创建一个 mongodata 目录:
- Now lets rerun the command but now like this :- mongod --dbpath d:\mongodata [shown in fig] this time you will not get and error
- 现在让我们重新运行命令,但现在像这样:- mongod --dbpath d:\mongodata [如图所示] 这次你不会得到和错误
- Hope everything is fine till this point .. open new command propmt [sufficent privellages (admin)]
- 希望到目前为止一切都很好..打开新命令 propmt [sufficent privellages (admin)]
colured in orange will be the command u need to run .. it will open the new command propmt which we known as mongo shell (or mongodb shell)
橙色将是您需要运行的命令..它将打开我们称为 mongo shell(或 mongodb shell)的新命令 propmt
11.dont close the shell[any of command promt as well] as in this we will create /delete/insert our databse operations
11.不要关闭外壳[任何命令提示符],因为在此我们将创建/删除/插入我们的数据库操作
- Lets perform basic operation
- 让我们执行基本操作
a) show databases b) show current databse c) creation of collection / inserting data into it (name will be test) d) show data of collection
a) 显示数据库 b) 显示当前数据库 c) 创建集合/将数据插入其中(名称将是测试) d) 显示集合数据
12.please find scrren shot of results of our operation .. please not :- dont close any command propmt
12.请找到我们操作结果的屏幕截图..请不要:-不要关闭任何命令提示
a diffrent structure type of number is object id :- which is created automatically
Hope you get some important info for installing mongodb DB.
数字的不同结构类型是对象 id :- 它是自动创建的
希望你能得到一些安装 mongodb DB 的重要信息。
回答by Jo Smo
1. Download MongoDB
1. 下载MongoDB
2. Install MongoDB
2.安装MongoDB
3. Create the required folders:
3. 创建所需的文件夹:
"C:\MongoDB_2_6_Standard\bin\data\db"
"C:\MongoDB_2_6_Standard\logs"
"C:\MongoDB_2_6_Standard\etc"
NOTE: If the directories do not exist, mongod.exe will not start.
注意:如果目录不存在,mongod.exe 将不会启动。
4. Create a simple configuration file:
4. 创建一个简单的配置文件:
systemLog:
destination: file
path: C:\MongoDB_2_6_Standard\logs\mongo.log
logAppend: true
net:
bindIp: 127.0.0.1
port: 27017
More info about how to create a configuration file: http://docs.mongodb.org/manual/reference/configuration-options/
有关如何创建配置文件的更多信息:http: //docs.mongodb.org/manual/reference/configuration-options/
5. Install MongoDB as a Windows Service (this way it will start automatically when you reboot your computer)
5. 将 MongoDB 安装为 Windows 服务(这样它会在您重新启动计算机时自动启动)
Run cmd with administrator privilegies, and enter the following commands:
以管理员权限运行cmd,输入以下命令:
"C:\MongoDB_2_6_Standard\bin\mongod.exe" --config "C:\MongoDB_2_6_Standard\etc\mongodb.conf" --dbpath c:\MongoDB_2_6_Standard\bin\data\db --directoryperdb --install
6. Start the MongoDB Windows Service
6. 启动 MongoDB Windows 服务
net start MongoDB
7. Connect to MongoDB via shell/cmd for testing
7.通过shell/cmd连接MongoDB进行测试
C:\MongoDB_2_6_Standard\bin\mongo.exe
NOTE: http://docs.mongodb.org/manual/tutorial/getting-started-with-the-mongo-shell/
注意:http: //docs.mongodb.org/manual/tutorial/getting-started-with-the-mongo-shell/
8. That's it! You are done. :)
8. 就是这样!你完成了。:)
9. Uninstall/remove the MongoDB Windows Service (if you messed up something)
9.卸载/删除MongoDB Windows服务(如果你搞砸了什么)
"C:\MongoDB_2_6_Standard\bin\mongod.exe" --remove
回答by Lawrine
Installing MongoDB on Windows is bit tricky compared to other Executable files.. Got a good reference after long search i got Installing MongoDB in Windows
与其他可执行文件相比,在 Windows 上安装 MongoDB 有点棘手。经过长时间的搜索,我得到了很好的参考,我得到了在 Windows 中安装 MongoDB
After Installing open command prompt and type "mongod", then keep the window minimized and open another command prompt window and type "mongo" and you will find the success message of connecting to the test database
安装后打开命令提示符输入“ mongod”,然后保持窗口最小化并打开另一个命令提示符窗口并输入“ mongo”,您将看到连接到测试数据库的成功信息
回答by Hitesh Sahu
Update Nov -2017
-2017 年 11 月更新
1) Go to Mongo DB download center https://www.mongodb.com/download-center#communityand pick a flavor of MongoDB you want to install. You can pick from
1) 转到 Mongo DB 下载中心https://www.mongodb.com/download-center#community并选择要安装的 MongoDB 版本。你可以从中挑选
- MongoDB Atlas- MongoDB database in the cloud
- Communiy Server- MongoDb for windows (with and without SSL),iOS, Linux
- OpManger- Mongo Db for Data Center
- Compass- UI tool for MongoDB
- MongoDB Atlas- 云中的 MongoDB 数据库
- Communiy Server- 适用于 Windows(带和不带 SSL)、iOS、Linux 的 MongoDb
- OpManger- 用于数据中心的 Mongo Db
- Compass- MongoDB 的 UI 工具
To know your OS version run this command in cmd prompt
要了解您的操作系统版本,请在 cmd 提示符下运行此命令
wmic os get caption
To know your CPU architecture(32 or 64 bit) run this command in cmd prompt
要了解您的 CPU 架构(32 位或 64 位),请在 cmd 提示符下运行此命令
wmic os get osarchitecture
I am using Community version (150MBs- GNU license)
我使用的是社区版(150MBs- GNU 许可证)
2) Click on MSI and go through installation Process. Exe will install MongoDb and SSL required by the DB.
2) 单击 MSI 并完成安装过程。Exe 将安装数据库所需的 MongoDb 和 SSL。
Mongo DB should be installed on your C drive
Mongo DB 应该安装在你的 C 盘上
C:\Program Files\MongoDB
C:\Program Files\MongoDB
MongoDB is self-contained, it means and does not have any other system dependencies. If you are low on disk in C drive then you can run MongoDB from any folder you choose.
MongoDB 是自包含的,这意味着并且没有任何其他系统依赖项。如果您的 C 盘磁盘空间不足,那么您可以从您选择的任何文件夹运行 MongoDB。
You can now run mongodb.exe from bin folder. If you get Visual C++ error for missing dlls then download Visual C++ Redistributable from
您现在可以从 bin 文件夹运行 mongodb.exe。如果您因缺少 dll 而收到 Visual C++ 错误,请从以下位置下载 Visual C++ Redistributable
https://www.microsoft.com/en-in/download/details.aspx?id=48145
https://www.microsoft.com/en-in/download/details.aspx?id=48145
After installation, try to rerun mongo.exe.
安装后,尝试重新运行 mongo.exe。
回答by Koustav
Download .msi from https://www.mongodb.com/download-center#community
Double click install - complete option
Installation folder C:\Program Files\MongoDB\Server\3.6\bin
Create database folder in C:// - c:/data/db and c:/data/log and c:/data/log/mongo.log and set write permission if not
Open cmd prompt in Administrator mode , navigate to C:\Program Files\MongoDB\Server\3.6\bin
Type the following
C:\Program Files\MongoDB\Server\3.6\bin>mongod --dbpath="c:/data/db" --logpath="c:/data/log/mongo.log"
Check folder c:/data/db - there should be many files and folder
Create a config file named "mongo.config" ** inside C:\data\
Type the following to set the config values from newly created config file
C:\Program Files\MongoDB\Server\3.6\bin>mongod --config C:\data\mongo.config
Open another new cmd prompt in Administrator mode , navigate to C:\Program Files\MongoDB\Server\3.6\bin execute the following lines on the console.
Type the following to create service for MongoDB
C:\Program Files\MongoDB\Server\3.6\bin>mongod --install --config C:\data\mongo.config --logpath="c:/data/log/mongo.log"
If old MongoDB service exists then need to delete the old service first before mongod --install command, run the following in a new console to delete old mongodb service
SC STOP MongoDB
>> SC DELETE MongoDB
Type the following to start MongoDB
C:\Program Files\MongoDB\Server\3.6\bin>net start MongoDB
Type the following to stop MongoDB
C:\Program Files\MongoDB\Server\3.6\bin>net stop MongoDB
双击安装 - 完整选项
安装文件夹 C:\Program Files\MongoDB\Server\3.6\bin
在 C:// - c:/data/db 和 c:/data/log 和 c:/data/log/mongo.log 中创建数据库文件夹,如果没有则设置写权限
在管理员模式下打开 cmd 提示符,导航到 C:\Program Files\MongoDB\Server\3.6\bin
输入以下内容
C:\Program Files\MongoDB\Server\3.6\bin>mongod --dbpath="c:/data/db" --logpath="c:/data/log/mongo.log"
检查文件夹 c:/data/db - 应该有很多文件和文件夹
在 C:\data\ 内创建一个名为“mongo.config”** 的配置文件
键入以下内容以从新创建的配置文件中设置配置值
C:\Program Files\MongoDB\Server\3.6\bin>mongod --config C:\data\mongo.config
在管理员模式下打开另一个新的 cmd 提示符,导航到 C:\Program Files\MongoDB\Server\3.6\bin 在控制台上执行以下几行。
键入以下内容为 MongoDB 创建服务
C:\Program Files\MongoDB\Server\3.6\bin>mongod --install --config C:\data\mongo.config --logpath="c:/data/log/mongo.log"
如果旧的MongoDB服务存在则需要在mongod --install命令之前先删除旧的服务,在新的控制台中运行以下命令删除旧的mongodb服务
SC 停止 MongoDB
>> SC DELETE MongoDB
键入以下内容以启动 MongoDB
C:\Program Files\MongoDB\Server\3.6\bin>net start MongoDB
键入以下内容以停止 MongoDB
C:\Program Files\MongoDB\Server\3.6\bin>net stop MongoDB
Now connect the DB on ip - 127.0.0.1 or 192.168.5.64 on port 27017 .
现在在端口 27017 上连接 ip - 127.0.0.1 或 192.168.5.64 上的数据库。
** File name - "mongo.config" , paste the following on config file -
** 文件名 - "mongo.config" ,在配置文件中粘贴以下内容 -
bind_ip = 127.0.0.1,192.168.5.64
bind_ip = 127.0.0.1,192.168.5.64
port = 27017
端口 = 27017
dbpath=C:\data\db
dbpath=C:\data\db
logpath=C:\data\log\mongo.log
日志路径=C:\data\log\mongo.log