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?

相关推荐
AllData公司负责人2 小时前
数据库同步平台|AIIData数据中台实现OceanBase、达梦数据库、OpenGauss、人大金仓、Hive、TDengine 一键接入Doris
大数据·数据库·hive·mysql·oceanbase·tdengine
2603_954708313 小时前
全维度容错设计,打造微电网安全运行屏障
服务器·网络·数据库·人工智能·分布式·安全
IvorySQL3 小时前
从双解析器到循环工程:IvorySQL 五年技术演进路线的深度观察
大数据·数据库·人工智能·postgresql·开源
YHHLAI3 小时前
Agent 智能体开发实战 · 第四课:完整工具集 —— 打造 AI 编程 Agent 的工具箱
人工智能·windows·microsoft
wefg13 小时前
【MySQL】事务
数据库·mysql
黑白极客3 小时前
mysql的高可用性
数据库·mysql
一十九的酒4 小时前
Oracle 12c 标准版无缝升级企业版实战记录
数据库·oracle·标准版切换到企业版
ZhengEnCi4 小时前
S02-SpringBoot实体类新增字段对已有数据的影响及自动DDL同步机制详解
数据库·spring boot
妙码生花4 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(三十二):增加 admin_rule 模型及数据表迁移
数据库·go·ai编程
千维百策6665 小时前
SRE 中如何消除琐务:提升工程效率与服务可靠性的实践方法
数据库