Install MongoDB as windows service

In this page I will show you how to install MongoDB in windows as service. Download MongoDB .msi file here and install. I assume that you install it in C:\Program Files\MongoDB. MongoDB will connect C:/data/db as default dbpath, if this directory doesn't exist you have to tell MongoDB the right dbpath. I create two directories for log(D:\mongo_data\log) and database(D:\mongo_data\db).

Start MongoDB Service

Before configuring MongoDB service you have to use following command to start MongoDB service.

复制代码
cd C:\Program Files\MongoDB\Server\3.0\bin
mongod.exe --dbpath D:\mongo_data\db

You will see the output like following

复制代码
2016-05-11T11:37:11.596+0800 I CONTROL  Hotfix KB2731284 or later update is not installed, will zero-out data files
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] MongoDB starting : pid=7188 port=27017 dbpath=D:\mongo_data\db 64-bit host=yong-PC
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] targetMinOS: Windows Server 2003 SP2
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] db version v3.0.10
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] git version: 1e0512f8453d103987f5fbfb87b71e9a131c2a60
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
2016-05-11T11:37:11.603+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2016-05-11T11:37:11.604+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "D:\mongo_data\db" } }
2016-05-11T11:37:11.613+0800 I JOURNAL  [initandlisten] journal dir=D:\mongo_data\db\journal
2016-05-11T11:37:11.614+0800 I JOURNAL  [initandlisten] recover : no journal files present, no recovery needed
2016-05-11T11:37:11.625+0800 I JOURNAL  [durability] Durability thread started
2016-05-11T11:37:11.626+0800 I JOURNAL  [journal writer] Journal writer thread started
2016-05-11T11:37:11.637+0800 I NETWORK  [initandlisten] waiting for connections on port 27017

You can press Ctrl + c to stop the service. As you can see it is a tedious process to start and stop the service. Next, I will show you how to configure MongoDB as windows service.

Configure MongoDB Service

Create a configuration file at C:\Program Files\MongoDB\Server\3.0\mongod.cfg like following.

复制代码
systemLog:
    destination: file
    path: D:\mongo_data\log\mongod.log
storage:
    dbPath: D:\mongo_data\db

Open windows command line and change directory to MongoDB installed and install MongoDB as windows Service

复制代码
cd C:\Program Files\MongoDB\Server\3.0\bin
mongod.exe --config "C:\Program Files\MongoDB\Server\3.0\mongod.cfg" --install

After executing the commands you can find MongoDB service in Windows Service Management(Win + R --> services.msc --> Enter)

You can create a shortcut to quick start and stop MongoDB service. How to create shortcut?

相关推荐
Hello.Reader38 分钟前
Redis 延迟监控深度指南
数据库·redis·缓存
ybq1951334543139 分钟前
Redis-主从复制-分布式系统
java·数据库·redis
好奇的菜鸟4 小时前
如何在IntelliJ IDEA中设置数据库连接全局共享
java·数据库·intellij-idea
tan180°4 小时前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql
程序视点4 小时前
Window 10文件拷贝总是卡很久?快来试试这款小工具,榨干硬盘速度!
windows
满昕欢喜4 小时前
SQL Server从入门到项目实践(超值版)读书笔记 20
数据库·sql·sqlserver
wuk9984 小时前
基于MATLAB编制的锂离子电池伪二维模型
linux·windows·github
Hello.Reader5 小时前
Redis 延迟排查与优化全攻略
数据库·redis·缓存
lzb_kkk5 小时前
【C++】C++四种类型转换操作符详解
开发语言·c++·windows·1024程序员节
简佐义的博客6 小时前
破解非模式物种GO/KEGG注释难题
开发语言·数据库·后端·oracle·golang