版本选择
- MongoDB for Windows 64-bit 适合 64 位的 Windows Server 2008 R2, Windows 7 , 及最新版本的 Window 系统。
- MongoDB for Windows 32-bit 适合 32 位的 Window 系统及最新的 Windows Vista。 32 位系统上 MongoDB 的数据库最大为 2GB。
注意:在 MongoDB3.2 版本后将不再提供32位版本。
- MongoDB for Windows 64-bit Legacy 适合 64 位的 Windows Vista, Windows Server 2003, 及 Windows Server 2008 。
MongoDB 下载
你可以从MongoDB官网下载地址(http://www.mongodb.org/downloads)下载最新版本的msi格式安装文件。
其他版本
MongoDB同时提供zip格式的安装包,可以在https://www.mongodb.org/dl/win32/x86_64找到各个版本的安装包,下载后将其解压就可以直接用了。
注意:ssl版本的zip包解压后需要libeay32.dll和ssleay32.dll两个文件的支持。
MongoDB 安装
对于msi格式的安装包,可以直接双击完成安装,通过Custom选项可以讲MongoDB安装到系统的任意目录。
对于zip格式的安装包,直接解压即可。
静默安装模式
MongoDB可以在命令行下(以管理员身份运行)使用msiexec.exe 来进行安装。命令如下:
1 |
msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.2.1-signed.msi INSTALLLOCATION="C:\mongodb" ADDLOCAL="all" |
INSTALLLOCATION 参数可以指定安装路径。
ADDLOCAL用以申明需要安装的组件,默认是全部安装的。MongoDB的各个组件和对应的二进制文件如下:
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 |
例如,只安装MongoDB 工具包, 可以用如下命令:
1 |
msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.2.1-signed.msi INSTALLLOCATION="C:\mongodb" ADDLOCAL="MonitoringTools,ImportExportTools,MiscellaneousTools" |
创建数据目录
MongoDB 需要一个目录来存放所有数据,默认的数据目录路径是\data\db。通过mongod.exe的启动参数—dbpath可以指定该目录,例如:
1 |
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data |
若路径中有空格,需要将该路径用半角双引号包起来,例如:
1 |
C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data" |
创建好目录后,即可启动使用MongoDB。
MongoDB的数据目录也可以通过配置文件来指定,详见下文。
命令行下运行 MongoDB 服务器
为了从命令提示符下运行MongoDB服务器,你必须从MongoDB安装目录的bin目录中执行mongod.exe文件。
1 |
mongod.exe --dbpath c:\data\db |
注意:MongoDB默认是无需权限验证的,如需添加权限,在参数中加入 —auth参数。
下表为mongodb的部分启动参数说明:
参数 |
描述 |
–bind_ip |
绑定服务IP,若绑定127.0.0.1,则只能本机访问,不指定默认本地所有IP |
–logpath |
定MongoDB日志文件,注意是指定文件不是目录 |
–logappend |
使用追加的方式写日志 |
–dbpath |
指定数据库路径 |
–port |
指定服务端口号,默认端口27017 |
–serviceName |
指定服务名称 |
–serviceDisplayNam |
指定服务名称,有多个mongodb服务时执行。 |
–install |
指定作为一个Windows服务安装。 |
将MongoDB服务器作为Windows服务运行
在mongodb的启动参数中加入 –install 即可将MongoDB作为windows的服务安装,例:
1 |
mongod.exe --bind_ip yourIPadress --logpath "C:\data\dbConf\mongodb.log" --logappend --dbpath "C:\data\db" --port yourPortNumber --serviceName "YourServiceName" --serviceDisplayName "YourServiceName" --install |
若要卸载该服务,在命令行执行下列命令:
1 |
\mongod.exe --remove |
MongoDB后台管理 Shell
在命令行中启动mongo.exe即可启动MongoDB 的后台管理Shell,MongoDB Shell是MongoDB自带的交互式Javascript shell,用来对MongoDB进行操作和管理的交互式环境。
当你进入mongoDB后台后,它默认会链接到 test 文档(数据库):
1 2 3 4 |
> mongo MongoDB shell version: 3.0.6 connecting to: test …… |
由于它是一个JavaScript shell,你还可以运行一些简单的算术运算:
1 2 3 4 |
> 2 + 2 4 > |
MongoDB的配置文件
MongoDB的配置文件格式和版本有关,2.6以后使用YAML作为配置文件的格式,YAML是一个类似于JSON的文本格式,需要注意的是,YAML不支持tab,需要用空格。
如下是一个配置文件的部分内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
systemLog: destination: file path: "/var/log/mongodb/mongod.log" logAppend: true storage: journal: enabled: true processManagement: fork: true net: bindIp: 127.0.0.1 port: 27017 setParameter: enableLocalhostAuthBypass: false ... |
在mongod和mongos启动时,可以使用配置文件代替参数输入。用法如下:
1 2 3 |
mongod --config /etc/mongod.conf mongos --config /etc/mongos.conf |
也可以使用 –f
1 2 3 |
mongod -f /etc/mongod.conf mongos -f /etc/mongos.conf |
配置文件的具体用法可以在官网的文档中找到详细的说明,https://docs.mongodb.org/manual/reference/configuration-options/。
side effects of domperidone for lactation domperidone buy painful spot on breast
orlistat 120mg capsules hard. latest update on orlistat Alli orlistat buy online – orlistat reducing side effects, will orlistat lower triglycerides,
Hi guys, I am Kelsie Davenport an expert in content writing.
I enjoy solving people’s problems and make them happy. That is what I have been doing for decades now.
I have been writing since I was 12 years old and never knew it would turn out to be a full-time career. I have also been able to manage several projects that involves writing. And I worked in three organizations as a volunteer to assist people.My passion has always been to help people succeed. And I go the extra mile to make that happen.
I enjoy writing academic papers and have helped people from countries like Australia.
I work with a service provider whose mission is to provide quality papers and make people happy. In fact, many people come to me for help on a daily basis because they know I always deliver. And I will continue to provide nothing but the best to build trust like I have been doing for the past few years.
Expert writer – Kelsie – supportthedandelionschool.com Team